@staffbase/plugins-client-sdk 1.2.3 → 2.0.0-beta.1
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/plugins-client-sdk.esm.js +377 -711
- package/dist/plugins-client-sdk.esm.js.map +1 -1
- package/dist/plugins-client-sdk.js +377 -713
- package/dist/plugins-client-sdk.js.map +1 -1
- package/dist/plugins-client-sdk.umd.js +377 -713
- package/dist/plugins-client-sdk.umd.js.map +1 -1
- package/dist/plugins-client-sdk.umd.min.js +3 -4
- package/dist/plugins-client-sdk.umd.min.js.map +1 -1
- package/package.json +36 -41
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
* Bundle of @staffbase/plugins-client-sdk
|
|
3
3
|
* @file Staffbase plugins client SDK for JavaScript
|
|
4
4
|
* @see https://github.com/Staffbase/plugins-client-sdk#readme
|
|
5
|
-
* @version 1.2.
|
|
5
|
+
* @version 1.2.3
|
|
6
6
|
*
|
|
7
7
|
* @author Stefan Staude <stefan.staude@staffbase.com>
|
|
8
8
|
* @author Daniel Große <daniel.grosse@staffbase.com>
|
|
9
9
|
*
|
|
10
|
-
* @copyright
|
|
10
|
+
* @copyright 2023
|
|
11
11
|
* @license Apache-2.0
|
|
12
12
|
*/
|
|
13
13
|
|
|
@@ -19,7 +19,11 @@
|
|
|
19
19
|
|
|
20
20
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
21
21
|
|
|
22
|
-
var
|
|
22
|
+
var loglevelExports = {};
|
|
23
|
+
var loglevel = {
|
|
24
|
+
get exports(){ return loglevelExports; },
|
|
25
|
+
set exports(v){ loglevelExports = v; },
|
|
26
|
+
};
|
|
23
27
|
|
|
24
28
|
/*
|
|
25
29
|
* loglevel - https://github.com/pimterry/loglevel
|
|
@@ -27,7 +31,6 @@
|
|
|
27
31
|
* Copyright (c) 2013 Tim Perry
|
|
28
32
|
* Licensed under the MIT license.
|
|
29
33
|
*/
|
|
30
|
-
|
|
31
34
|
(function (module) {
|
|
32
35
|
(function (root, definition) {
|
|
33
36
|
|
|
@@ -38,15 +41,15 @@
|
|
|
38
41
|
}
|
|
39
42
|
})(commonjsGlobal, function () {
|
|
40
43
|
|
|
44
|
+
// Slightly dubious tricks to cut down minimized file size
|
|
41
45
|
var noop = function () {};
|
|
42
|
-
|
|
43
46
|
var undefinedType = "undefined";
|
|
44
47
|
var isIE = typeof window !== undefinedType && typeof window.navigator !== undefinedType && /Trident\/|MSIE /.test(window.navigator.userAgent);
|
|
45
|
-
var logMethods = ["trace", "debug", "info", "warn", "error"];
|
|
48
|
+
var logMethods = ["trace", "debug", "info", "warn", "error"];
|
|
46
49
|
|
|
50
|
+
// Cross-browser bind equivalent that works at least back to IE6
|
|
47
51
|
function bindMethod(obj, methodName) {
|
|
48
52
|
var method = obj[methodName];
|
|
49
|
-
|
|
50
53
|
if (typeof method.bind === 'function') {
|
|
51
54
|
return method.bind(obj);
|
|
52
55
|
} else {
|
|
@@ -59,9 +62,9 @@
|
|
|
59
62
|
};
|
|
60
63
|
}
|
|
61
64
|
}
|
|
62
|
-
}
|
|
63
|
-
|
|
65
|
+
}
|
|
64
66
|
|
|
67
|
+
// Trace() doesn't print the message in IE, so for that case we need to wrap it
|
|
65
68
|
function traceForIE() {
|
|
66
69
|
if (console.log) {
|
|
67
70
|
if (console.log.apply) {
|
|
@@ -71,17 +74,15 @@
|
|
|
71
74
|
Function.prototype.apply.apply(console.log, [console, arguments]);
|
|
72
75
|
}
|
|
73
76
|
}
|
|
74
|
-
|
|
75
77
|
if (console.trace) console.trace();
|
|
76
|
-
}
|
|
77
|
-
// Wherever possible we want to bind, not wrap, to preserve stack traces
|
|
78
|
-
|
|
78
|
+
}
|
|
79
79
|
|
|
80
|
+
// Build the best logging method possible for this env
|
|
81
|
+
// Wherever possible we want to bind, not wrap, to preserve stack traces
|
|
80
82
|
function realMethod(methodName) {
|
|
81
83
|
if (methodName === 'debug') {
|
|
82
84
|
methodName = 'log';
|
|
83
85
|
}
|
|
84
|
-
|
|
85
86
|
if (typeof console === undefinedType) {
|
|
86
87
|
return false; // No method possible, for now - fixed later by enableLoggingWhenConsoleArrives
|
|
87
88
|
} else if (methodName === 'trace' && isIE) {
|
|
@@ -93,22 +94,23 @@
|
|
|
93
94
|
} else {
|
|
94
95
|
return noop;
|
|
95
96
|
}
|
|
96
|
-
}
|
|
97
|
+
}
|
|
97
98
|
|
|
99
|
+
// These private functions always need `this` to be set properly
|
|
98
100
|
|
|
99
101
|
function replaceLoggingMethods(level, loggerName) {
|
|
100
102
|
/*jshint validthis:true */
|
|
101
103
|
for (var i = 0; i < logMethods.length; i++) {
|
|
102
104
|
var methodName = logMethods[i];
|
|
103
105
|
this[methodName] = i < level ? noop : this.methodFactory(methodName, level, loggerName);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
+
}
|
|
106
107
|
|
|
108
|
+
// Define log.log as an alias for log.debug
|
|
107
109
|
this.log = this.debug;
|
|
108
|
-
}
|
|
109
|
-
// We build realMethod() replacements here that regenerate logging methods
|
|
110
|
-
|
|
110
|
+
}
|
|
111
111
|
|
|
112
|
+
// In old IE versions, the console isn't present until you first open it.
|
|
113
|
+
// We build realMethod() replacements here that regenerate logging methods
|
|
112
114
|
function enableLoggingWhenConsoleArrives(methodName, level, loggerName) {
|
|
113
115
|
return function () {
|
|
114
116
|
if (typeof console !== undefinedType) {
|
|
@@ -116,90 +118,84 @@
|
|
|
116
118
|
this[methodName].apply(this, arguments);
|
|
117
119
|
}
|
|
118
120
|
};
|
|
119
|
-
}
|
|
120
|
-
// otherwise we wait for a console to appear, and then try again.
|
|
121
|
-
|
|
121
|
+
}
|
|
122
122
|
|
|
123
|
+
// By default, we use closely bound real methods wherever possible, and
|
|
124
|
+
// otherwise we wait for a console to appear, and then try again.
|
|
123
125
|
function defaultMethodFactory(methodName, level, loggerName) {
|
|
124
126
|
/*jshint validthis:true */
|
|
125
127
|
return realMethod(methodName) || enableLoggingWhenConsoleArrives.apply(this, arguments);
|
|
126
128
|
}
|
|
127
|
-
|
|
128
129
|
function Logger(name, defaultLevel, factory) {
|
|
129
130
|
var self = this;
|
|
130
131
|
var currentLevel;
|
|
131
132
|
defaultLevel = defaultLevel == null ? "WARN" : defaultLevel;
|
|
132
133
|
var storageKey = "loglevel";
|
|
133
|
-
|
|
134
134
|
if (typeof name === "string") {
|
|
135
135
|
storageKey += ":" + name;
|
|
136
136
|
} else if (typeof name === "symbol") {
|
|
137
137
|
storageKey = undefined;
|
|
138
138
|
}
|
|
139
|
-
|
|
140
139
|
function persistLevelIfPossible(levelNum) {
|
|
141
140
|
var levelName = (logMethods[levelNum] || 'silent').toUpperCase();
|
|
142
|
-
if (typeof window === undefinedType || !storageKey) return;
|
|
141
|
+
if (typeof window === undefinedType || !storageKey) return;
|
|
143
142
|
|
|
143
|
+
// Use localStorage if available
|
|
144
144
|
try {
|
|
145
145
|
window.localStorage[storageKey] = levelName;
|
|
146
146
|
return;
|
|
147
|
-
} catch (ignore) {}
|
|
148
|
-
|
|
147
|
+
} catch (ignore) {}
|
|
149
148
|
|
|
149
|
+
// Use session cookie as fallback
|
|
150
150
|
try {
|
|
151
151
|
window.document.cookie = encodeURIComponent(storageKey) + "=" + levelName + ";";
|
|
152
152
|
} catch (ignore) {}
|
|
153
153
|
}
|
|
154
|
-
|
|
155
154
|
function getPersistedLevel() {
|
|
156
155
|
var storedLevel;
|
|
157
156
|
if (typeof window === undefinedType || !storageKey) return;
|
|
158
|
-
|
|
159
157
|
try {
|
|
160
158
|
storedLevel = window.localStorage[storageKey];
|
|
161
|
-
} catch (ignore) {}
|
|
162
|
-
|
|
159
|
+
} catch (ignore) {}
|
|
163
160
|
|
|
161
|
+
// Fallback to cookies if local storage gives us nothing
|
|
164
162
|
if (typeof storedLevel === undefinedType) {
|
|
165
163
|
try {
|
|
166
164
|
var cookie = window.document.cookie;
|
|
167
165
|
var location = cookie.indexOf(encodeURIComponent(storageKey) + "=");
|
|
168
|
-
|
|
169
166
|
if (location !== -1) {
|
|
170
167
|
storedLevel = /^([^;]+)/.exec(cookie.slice(location))[1];
|
|
171
168
|
}
|
|
172
169
|
} catch (ignore) {}
|
|
173
|
-
}
|
|
174
|
-
|
|
170
|
+
}
|
|
175
171
|
|
|
172
|
+
// If the stored level is not valid, treat it as if nothing was stored.
|
|
176
173
|
if (self.levels[storedLevel] === undefined) {
|
|
177
174
|
storedLevel = undefined;
|
|
178
175
|
}
|
|
179
|
-
|
|
180
176
|
return storedLevel;
|
|
181
177
|
}
|
|
182
|
-
|
|
183
178
|
function clearPersistedLevel() {
|
|
184
|
-
if (typeof window === undefinedType || !storageKey) return;
|
|
179
|
+
if (typeof window === undefinedType || !storageKey) return;
|
|
185
180
|
|
|
181
|
+
// Use localStorage if available
|
|
186
182
|
try {
|
|
187
183
|
window.localStorage.removeItem(storageKey);
|
|
188
184
|
return;
|
|
189
|
-
} catch (ignore) {}
|
|
190
|
-
|
|
185
|
+
} catch (ignore) {}
|
|
191
186
|
|
|
187
|
+
// Use session cookie as fallback
|
|
192
188
|
try {
|
|
193
189
|
window.document.cookie = encodeURIComponent(storageKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
|
|
194
190
|
} catch (ignore) {}
|
|
195
191
|
}
|
|
192
|
+
|
|
196
193
|
/*
|
|
197
194
|
*
|
|
198
195
|
* Public logger API - see https://github.com/pimterry/loglevel for details
|
|
199
196
|
*
|
|
200
197
|
*/
|
|
201
198
|
|
|
202
|
-
|
|
203
199
|
self.name = name;
|
|
204
200
|
self.levels = {
|
|
205
201
|
"TRACE": 0,
|
|
@@ -210,26 +206,20 @@
|
|
|
210
206
|
"SILENT": 5
|
|
211
207
|
};
|
|
212
208
|
self.methodFactory = factory || defaultMethodFactory;
|
|
213
|
-
|
|
214
209
|
self.getLevel = function () {
|
|
215
210
|
return currentLevel;
|
|
216
211
|
};
|
|
217
|
-
|
|
218
212
|
self.setLevel = function (level, persist) {
|
|
219
213
|
if (typeof level === "string" && self.levels[level.toUpperCase()] !== undefined) {
|
|
220
214
|
level = self.levels[level.toUpperCase()];
|
|
221
215
|
}
|
|
222
|
-
|
|
223
216
|
if (typeof level === "number" && level >= 0 && level <= self.levels.SILENT) {
|
|
224
217
|
currentLevel = level;
|
|
225
|
-
|
|
226
218
|
if (persist !== false) {
|
|
227
219
|
// defaults to true
|
|
228
220
|
persistLevelIfPossible(level);
|
|
229
221
|
}
|
|
230
|
-
|
|
231
222
|
replaceLoggingMethods.call(self, level, name);
|
|
232
|
-
|
|
233
223
|
if (typeof console === undefinedType && level < self.levels.SILENT) {
|
|
234
224
|
return "No console available for logging";
|
|
235
225
|
}
|
|
@@ -237,179 +227,93 @@
|
|
|
237
227
|
throw "log.setLevel() called with invalid level: " + level;
|
|
238
228
|
}
|
|
239
229
|
};
|
|
240
|
-
|
|
241
230
|
self.setDefaultLevel = function (level) {
|
|
242
231
|
defaultLevel = level;
|
|
243
|
-
|
|
244
232
|
if (!getPersistedLevel()) {
|
|
245
233
|
self.setLevel(level, false);
|
|
246
234
|
}
|
|
247
235
|
};
|
|
248
|
-
|
|
249
236
|
self.resetLevel = function () {
|
|
250
237
|
self.setLevel(defaultLevel, false);
|
|
251
238
|
clearPersistedLevel();
|
|
252
239
|
};
|
|
253
|
-
|
|
254
240
|
self.disableAll = function (persist) {
|
|
255
241
|
self.setLevel(self.levels.SILENT, persist);
|
|
256
|
-
};
|
|
257
|
-
|
|
242
|
+
};
|
|
258
243
|
|
|
244
|
+
// Initialize with the right level
|
|
259
245
|
var initialLevel = getPersistedLevel();
|
|
260
|
-
|
|
261
246
|
if (initialLevel == null) {
|
|
262
247
|
initialLevel = defaultLevel;
|
|
263
248
|
}
|
|
264
|
-
|
|
265
249
|
self.setLevel(initialLevel, false);
|
|
266
250
|
}
|
|
251
|
+
|
|
267
252
|
/*
|
|
268
253
|
*
|
|
269
254
|
* Top-level API
|
|
270
255
|
*
|
|
271
256
|
*/
|
|
272
257
|
|
|
273
|
-
|
|
274
258
|
var defaultLogger = new Logger();
|
|
275
259
|
var _loggersByName = {};
|
|
276
|
-
|
|
277
260
|
defaultLogger.getLogger = function getLogger(name) {
|
|
278
261
|
if (typeof name !== "symbol" && typeof name !== "string" || name === "") {
|
|
279
262
|
throw new TypeError("You must supply a name when creating a logger.");
|
|
280
263
|
}
|
|
281
|
-
|
|
282
264
|
var logger = _loggersByName[name];
|
|
283
|
-
|
|
284
265
|
if (!logger) {
|
|
285
266
|
logger = _loggersByName[name] = new Logger(name, defaultLogger.getLevel(), defaultLogger.methodFactory);
|
|
286
267
|
}
|
|
287
|
-
|
|
288
268
|
return logger;
|
|
289
|
-
};
|
|
290
|
-
|
|
269
|
+
};
|
|
291
270
|
|
|
271
|
+
// Grab the current global log variable in case of overwrite
|
|
292
272
|
var _log = typeof window !== undefinedType ? window.log : undefined;
|
|
293
|
-
|
|
294
273
|
defaultLogger.noConflict = function () {
|
|
295
274
|
if (typeof window !== undefinedType && window.log === defaultLogger) {
|
|
296
275
|
window.log = _log;
|
|
297
276
|
}
|
|
298
|
-
|
|
299
277
|
return defaultLogger;
|
|
300
278
|
};
|
|
301
|
-
|
|
302
279
|
defaultLogger.getLoggers = function getLoggers() {
|
|
303
280
|
return _loggersByName;
|
|
304
|
-
};
|
|
305
|
-
|
|
281
|
+
};
|
|
306
282
|
|
|
283
|
+
// ES6 default export, for compatibility
|
|
307
284
|
defaultLogger['default'] = defaultLogger;
|
|
308
285
|
return defaultLogger;
|
|
309
286
|
});
|
|
310
287
|
})(loglevel);
|
|
311
288
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
obj
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
function _slicedToArray(arr, i) {
|
|
328
|
-
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
function _arrayWithHoles(arr) {
|
|
332
|
-
if (Array.isArray(arr)) return arr;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
function _iterableToArrayLimit(arr, i) {
|
|
336
|
-
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
337
|
-
|
|
338
|
-
if (_i == null) return;
|
|
339
|
-
var _arr = [];
|
|
340
|
-
var _n = true;
|
|
341
|
-
var _d = false;
|
|
342
|
-
|
|
343
|
-
var _s, _e;
|
|
344
|
-
|
|
345
|
-
try {
|
|
346
|
-
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
|
|
347
|
-
_arr.push(_s.value);
|
|
348
|
-
|
|
349
|
-
if (i && _arr.length === i) break;
|
|
350
|
-
}
|
|
351
|
-
} catch (err) {
|
|
352
|
-
_d = true;
|
|
353
|
-
_e = err;
|
|
354
|
-
} finally {
|
|
355
|
-
try {
|
|
356
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
357
|
-
} finally {
|
|
358
|
-
if (_d) throw _e;
|
|
289
|
+
var entries_1;
|
|
290
|
+
var hasRequiredEntries;
|
|
291
|
+
function requireEntries() {
|
|
292
|
+
if (hasRequiredEntries) return entries_1;
|
|
293
|
+
hasRequiredEntries = 1;
|
|
294
|
+
var has = function (obj, prop) {
|
|
295
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
296
|
+
};
|
|
297
|
+
var isEnumerable = function (obj, prop) {
|
|
298
|
+
return Object.prototype.propertyIsEnumerable.call(obj, prop);
|
|
299
|
+
};
|
|
300
|
+
function entries(obj) {
|
|
301
|
+
if (obj == null) {
|
|
302
|
+
throw new TypeError('Cannot convert undefined or null to object');
|
|
359
303
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
366
|
-
if (!o) return;
|
|
367
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
368
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
369
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
370
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
371
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
function _arrayLikeToArray(arr, len) {
|
|
375
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
376
|
-
|
|
377
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
378
|
-
|
|
379
|
-
return arr2;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
function _nonIterableRest() {
|
|
383
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
var has = function (obj, prop) {
|
|
387
|
-
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
388
|
-
};
|
|
389
|
-
|
|
390
|
-
var isEnumerable = function (obj, prop) {
|
|
391
|
-
return Object.prototype.propertyIsEnumerable.call(obj, prop);
|
|
392
|
-
};
|
|
393
|
-
|
|
394
|
-
function entries(obj) {
|
|
395
|
-
if (obj == null) {
|
|
396
|
-
throw new TypeError('Cannot convert undefined or null to object');
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
var pairs = [];
|
|
400
|
-
|
|
401
|
-
for (var key in obj) {
|
|
402
|
-
if (has(obj, key) && isEnumerable(obj, key)) {
|
|
403
|
-
pairs.push([key, obj[key]]);
|
|
304
|
+
var pairs = [];
|
|
305
|
+
for (var key in obj) {
|
|
306
|
+
if (has(obj, key) && isEnumerable(obj, key)) {
|
|
307
|
+
pairs.push([key, obj[key]]);
|
|
308
|
+
}
|
|
404
309
|
}
|
|
310
|
+
return pairs;
|
|
405
311
|
}
|
|
406
|
-
|
|
407
|
-
return
|
|
312
|
+
entries_1 = entries;
|
|
313
|
+
return entries_1;
|
|
408
314
|
}
|
|
409
315
|
|
|
410
|
-
var
|
|
411
|
-
|
|
412
|
-
var object_entriesPonyfill = typeof Object.entries === 'function' ? Object.entries : entries_1;
|
|
316
|
+
var object_entriesPonyfill = typeof Object.entries === 'function' ? Object.entries : requireEntries();
|
|
413
317
|
|
|
414
318
|
/**
|
|
415
319
|
* Reverses the keys and properties of the given object
|
|
@@ -417,17 +321,11 @@
|
|
|
417
321
|
* @param {object} obj the object to reverse
|
|
418
322
|
* @return {object}
|
|
419
323
|
*/
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
p = _ref2[1];
|
|
426
|
-
|
|
427
|
-
acc[p] = k;
|
|
428
|
-
return acc;
|
|
429
|
-
}, {});
|
|
430
|
-
};
|
|
324
|
+
const reverse = obj => object_entriesPonyfill(obj).reduce((acc, _ref) => {
|
|
325
|
+
let [k, p] = _ref;
|
|
326
|
+
acc[p] = k;
|
|
327
|
+
return acc;
|
|
328
|
+
}, {});
|
|
431
329
|
|
|
432
330
|
/**
|
|
433
331
|
* @typedef { Object.<string, string> } PlatformCommands
|
|
@@ -440,8 +338,7 @@
|
|
|
440
338
|
*
|
|
441
339
|
* @type {PlatformCommands}
|
|
442
340
|
*/
|
|
443
|
-
|
|
444
|
-
var commands = {
|
|
341
|
+
const commands = {
|
|
445
342
|
ios: 'dev-ios',
|
|
446
343
|
android: 'dev-android',
|
|
447
344
|
version: 'app-version',
|
|
@@ -454,13 +351,13 @@
|
|
|
454
351
|
branchDefaultLang: 'getBranchDefaultLanguage',
|
|
455
352
|
prefContentLang: 'getPreferredContentLocale'
|
|
456
353
|
};
|
|
354
|
+
|
|
457
355
|
/**
|
|
458
356
|
* All supported commands with reversed keys and properties
|
|
459
357
|
*
|
|
460
358
|
* @type {ReversedPlatformCommands>}
|
|
461
359
|
*/
|
|
462
|
-
|
|
463
|
-
var reversedCommands = reverse(commands);
|
|
360
|
+
const reversedCommands = reverse(commands);
|
|
464
361
|
|
|
465
362
|
var locales = {
|
|
466
363
|
af: {
|
|
@@ -897,29 +794,28 @@
|
|
|
897
794
|
*
|
|
898
795
|
* @return {string} the first part of the locale
|
|
899
796
|
*/
|
|
900
|
-
|
|
797
|
+
const normalize = locale => {
|
|
901
798
|
locale = locale && locale.split(/-|_/)[0] || locale; // use only first part
|
|
902
799
|
|
|
903
800
|
if (['nb', 'nn'].indexOf(locale) !== -1) {
|
|
904
801
|
// fix Norwegian language code to conform with our non-standard stuff
|
|
905
802
|
locale = 'no';
|
|
906
803
|
}
|
|
907
|
-
|
|
908
804
|
if (locale === 'iw') {
|
|
909
805
|
// fix legacy Hebrew language code from our backend to conform with our frontend
|
|
910
806
|
locale = 'he';
|
|
911
807
|
}
|
|
912
|
-
|
|
913
808
|
return locale;
|
|
914
809
|
};
|
|
915
810
|
|
|
916
811
|
/**
|
|
917
812
|
* Fallbacks for all sdk commands
|
|
918
813
|
*/
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
// in case of executeJs of app version 3.5 this object gets overwritten
|
|
814
|
+
const userAgent = navigator.userAgent || navigator.vendor || window.opera || '';
|
|
815
|
+
const currentLanguage = normalize(window && window.navigator.language);
|
|
922
816
|
|
|
817
|
+
// initialize Staffbase/platform namespace for ios frontend js code injection
|
|
818
|
+
// in case of executeJs of app version 3.5 this object gets overwritten
|
|
923
819
|
if (typeof window !== 'undefined') {
|
|
924
820
|
window.Staffbase = window.Staffbase || {};
|
|
925
821
|
window.Staffbase.platform = window.Staffbase.platform || {
|
|
@@ -928,81 +824,80 @@
|
|
|
928
824
|
native: false
|
|
929
825
|
};
|
|
930
826
|
}
|
|
827
|
+
|
|
931
828
|
/**
|
|
932
829
|
* Get the current Staffbase app version
|
|
933
830
|
*
|
|
934
831
|
* @return {String} version
|
|
935
832
|
*/
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
var getVersion$1 = function getVersion() {
|
|
833
|
+
const getVersion$1 = () => {
|
|
939
834
|
return window.Staffbase.platform.version;
|
|
940
835
|
};
|
|
836
|
+
|
|
941
837
|
/**
|
|
942
838
|
* Are we running in a native app
|
|
943
839
|
*
|
|
944
840
|
* works only for ios or old initial native data
|
|
945
841
|
* @return {Boolean}
|
|
946
842
|
*/
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
var safari = /safari/i.test(userAgent);
|
|
843
|
+
const isNative$1 = () => {
|
|
844
|
+
const safari = /safari/i.test(userAgent);
|
|
950
845
|
return window.Staffbase.platform.native === 'android' || window.Staffbase.platform.native === 'ios' || !safari && isIos$1();
|
|
951
846
|
};
|
|
847
|
+
|
|
952
848
|
/**
|
|
953
849
|
* Are we running on a mobile device
|
|
954
850
|
*
|
|
955
851
|
* @return {Boolean}
|
|
956
852
|
*/
|
|
957
|
-
|
|
958
|
-
var isMobile$1 = function isMobile() {
|
|
853
|
+
const isMobile$1 = () => {
|
|
959
854
|
return window.Staffbase.platform.mobile;
|
|
960
855
|
};
|
|
856
|
+
|
|
961
857
|
/**
|
|
962
858
|
* Are we running on android
|
|
963
859
|
*
|
|
964
860
|
* @return {Boolean}
|
|
965
861
|
*/
|
|
966
|
-
|
|
967
|
-
var isAndroid$1 = function isAndroid() {
|
|
862
|
+
const isAndroid$1 = () => {
|
|
968
863
|
return window.Staffbase.platform.native === 'android' || /Android/i.test(userAgent);
|
|
969
864
|
};
|
|
865
|
+
|
|
970
866
|
/**
|
|
971
867
|
* Are we running on ios
|
|
972
868
|
*
|
|
973
869
|
* @return {Boolean}
|
|
974
870
|
*/
|
|
975
|
-
|
|
976
|
-
var isIos$1 = function isIos() {
|
|
871
|
+
const isIos$1 = () => {
|
|
977
872
|
return window.Staffbase.platform.native === 'ios' || /iPhone|iPad|iPod/i.test(userAgent);
|
|
978
873
|
};
|
|
874
|
+
|
|
979
875
|
/**
|
|
980
876
|
* Open an external link
|
|
981
877
|
*
|
|
982
878
|
* @param {String} url address
|
|
983
879
|
*/
|
|
984
|
-
|
|
985
|
-
var openLink$2 = function openLink(url) {
|
|
880
|
+
const openLink$2 = url => {
|
|
986
881
|
window.open(url, '_blank');
|
|
987
882
|
};
|
|
883
|
+
|
|
988
884
|
/**
|
|
989
885
|
* Handler for unpossible functions
|
|
990
886
|
*
|
|
991
887
|
* @param {String} cmd command name
|
|
992
888
|
*/
|
|
993
|
-
|
|
994
|
-
var unSupported = function unSupported(cmd) {
|
|
889
|
+
const unSupported = cmd => {
|
|
995
890
|
// nothing we can do here
|
|
996
891
|
return;
|
|
997
892
|
};
|
|
893
|
+
|
|
998
894
|
/**
|
|
999
895
|
* Get extensive locale information.
|
|
1000
896
|
*
|
|
1001
897
|
* @return {Object} containing various language informations
|
|
1002
898
|
*/
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
var branchDefaultLanguage = getBranchDefaultLanguage$2();
|
|
899
|
+
const langInfos = () => {
|
|
900
|
+
const branchDefaultLanguage = getBranchDefaultLanguage$2();
|
|
1006
901
|
return {
|
|
1007
902
|
contentLanguage: branchDefaultLanguage,
|
|
1008
903
|
branchLanguages: locales,
|
|
@@ -1011,15 +906,16 @@
|
|
|
1011
906
|
contentLanguages: locales
|
|
1012
907
|
};
|
|
1013
908
|
};
|
|
909
|
+
|
|
1014
910
|
/**
|
|
1015
911
|
* Get the default language object
|
|
1016
912
|
*
|
|
1017
913
|
* @return {Object} the language object
|
|
1018
914
|
*/
|
|
1019
|
-
|
|
1020
|
-
var getBranchDefaultLanguage$2 = function getBranchDefaultLanguage() {
|
|
915
|
+
const getBranchDefaultLanguage$2 = () => {
|
|
1021
916
|
return locales[currentLanguage] || locales.en;
|
|
1022
917
|
};
|
|
918
|
+
|
|
1023
919
|
/**
|
|
1024
920
|
* Gets the chosen language from a given content object
|
|
1025
921
|
*
|
|
@@ -1027,28 +923,24 @@
|
|
|
1027
923
|
*
|
|
1028
924
|
* @return {string}
|
|
1029
925
|
*/
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
var locale = getBranchDefaultLanguage$2().locale;
|
|
1033
|
-
|
|
926
|
+
const getPreferredContentLocale$2 = content => {
|
|
927
|
+
const locale = getBranchDefaultLanguage$2().locale;
|
|
1034
928
|
if (!content) {
|
|
1035
929
|
return locale;
|
|
1036
930
|
}
|
|
1037
|
-
|
|
1038
931
|
if (Array.isArray(content)) {
|
|
1039
|
-
|
|
932
|
+
const index = content.indexOf(locale);
|
|
1040
933
|
return content[index] || content[0];
|
|
1041
934
|
} else {
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
return keys[_index] || keys[0];
|
|
935
|
+
const keys = Object.keys(content);
|
|
936
|
+
const index = keys.indexOf(locale);
|
|
937
|
+
return keys[index] || keys[0];
|
|
1047
938
|
}
|
|
1048
939
|
};
|
|
1049
940
|
|
|
1050
|
-
|
|
1051
|
-
|
|
941
|
+
let connection$2 = null;
|
|
942
|
+
const fallbackKickIn = 500;
|
|
943
|
+
|
|
1052
944
|
/**
|
|
1053
945
|
* Fake connection to the Staffbase App after a period of time.
|
|
1054
946
|
*
|
|
@@ -1056,19 +948,18 @@
|
|
|
1056
948
|
* after the time specified in fallbackKickIn runs out.
|
|
1057
949
|
* @return {Promise<function>} An appropriate send function
|
|
1058
950
|
*/
|
|
1059
|
-
|
|
1060
|
-
var fallback = (function () {
|
|
951
|
+
var fallback = (() => {
|
|
1061
952
|
if (connection$2) {
|
|
1062
953
|
return connection$2;
|
|
1063
954
|
}
|
|
1064
|
-
|
|
1065
|
-
connection$2 = new Promise(function (resolve) {
|
|
955
|
+
connection$2 = new Promise(resolve => {
|
|
1066
956
|
setTimeout(function () {
|
|
1067
957
|
resolve(sendMessage$3);
|
|
1068
958
|
}, fallbackKickIn);
|
|
1069
959
|
});
|
|
1070
960
|
return connection$2;
|
|
1071
961
|
});
|
|
962
|
+
|
|
1072
963
|
/**
|
|
1073
964
|
* Send a SDK command to the Staffbase App.
|
|
1074
965
|
*
|
|
@@ -1078,56 +969,38 @@
|
|
|
1078
969
|
* @return {Promise<any>} which awaits the response of the Staffbase App
|
|
1079
970
|
* @throws {Error} on commands not supported by protocol
|
|
1080
971
|
*/
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
case commands.branchDefaultLang:
|
|
1112
|
-
return $return(getBranchDefaultLanguage$2());
|
|
1113
|
-
|
|
1114
|
-
case commands.prefContentLang:
|
|
1115
|
-
return $return(getPreferredContentLocale$2.apply(null, payload));
|
|
1116
|
-
|
|
1117
|
-
case commands.nativeUpload:
|
|
1118
|
-
case commands.nativeShare:
|
|
1119
|
-
return $return(unSupported());
|
|
1120
|
-
|
|
1121
|
-
default:
|
|
1122
|
-
// should actually never ever happen
|
|
1123
|
-
return $error(new Error('Command ' + cmd + ' not supported by driver'));
|
|
1124
|
-
}
|
|
1125
|
-
|
|
1126
|
-
return $return();
|
|
1127
|
-
});
|
|
972
|
+
const sendMessage$3 = async function (cmd) {
|
|
973
|
+
for (var _len = arguments.length, payload = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
974
|
+
payload[_key - 1] = arguments[_key];
|
|
975
|
+
}
|
|
976
|
+
switch (cmd) {
|
|
977
|
+
case commands.version:
|
|
978
|
+
return getVersion$1();
|
|
979
|
+
case commands.native:
|
|
980
|
+
return isNative$1();
|
|
981
|
+
case commands.mobile:
|
|
982
|
+
return isMobile$1();
|
|
983
|
+
case commands.ios:
|
|
984
|
+
return isIos$1();
|
|
985
|
+
case commands.android:
|
|
986
|
+
return isAndroid$1();
|
|
987
|
+
case commands.openLink:
|
|
988
|
+
return openLink$2.apply(null, payload);
|
|
989
|
+
case commands.langInfos:
|
|
990
|
+
return langInfos();
|
|
991
|
+
case commands.branchDefaultLang:
|
|
992
|
+
return getBranchDefaultLanguage$2();
|
|
993
|
+
case commands.prefContentLang:
|
|
994
|
+
return getPreferredContentLocale$2.apply(null, payload);
|
|
995
|
+
case commands.nativeUpload:
|
|
996
|
+
case commands.nativeShare:
|
|
997
|
+
return unSupported();
|
|
998
|
+
default:
|
|
999
|
+
// should actually never ever happen
|
|
1000
|
+
throw new Error('Command ' + cmd + ' not supported by driver');
|
|
1001
|
+
}
|
|
1128
1002
|
};
|
|
1129
1003
|
|
|
1130
|
-
var _invocationMapping;
|
|
1131
1004
|
/**
|
|
1132
1005
|
* Postmessage protocol (3.6)
|
|
1133
1006
|
*/
|
|
@@ -1140,33 +1013,39 @@
|
|
|
1140
1013
|
INVOCATION: 'INVOCATION',
|
|
1141
1014
|
// send this to call a function in the frontend
|
|
1142
1015
|
ERROR: 'ERROR' // receive this when something goes wrong
|
|
1016
|
+
};
|
|
1143
1017
|
|
|
1018
|
+
const invocationMapping = {
|
|
1019
|
+
[commands.openLink]: 'openLink',
|
|
1020
|
+
[commands.nativeUpload]: 'nativeFileUpload',
|
|
1021
|
+
[commands.nativeShare]: 'nativeShareDialog',
|
|
1022
|
+
[commands.langInfos]: 'getPluginLanguageInfo',
|
|
1023
|
+
[commands.prefContentLang]: 'getPreferredContentLocale'
|
|
1144
1024
|
};
|
|
1145
|
-
var invocationMapping = (_invocationMapping = {}, _defineProperty(_invocationMapping, commands.openLink, 'openLink'), _defineProperty(_invocationMapping, commands.nativeUpload, 'nativeFileUpload'), _defineProperty(_invocationMapping, commands.nativeShare, 'nativeShareDialog'), _defineProperty(_invocationMapping, commands.langInfos, 'getPluginLanguageInfo'), _defineProperty(_invocationMapping, commands.prefContentLang, 'getPreferredContentLocale'), _invocationMapping);
|
|
1146
1025
|
|
|
1147
1026
|
/**
|
|
1148
1027
|
* Generates an unique id of 4 alpha numerical chars
|
|
1149
1028
|
*
|
|
1150
1029
|
* @return {string} unique id
|
|
1151
1030
|
*/
|
|
1152
|
-
|
|
1031
|
+
const genID = () => {
|
|
1153
1032
|
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
|
|
1154
1033
|
};
|
|
1155
1034
|
|
|
1156
1035
|
/**
|
|
1157
1036
|
* @type {Object.<string, {resolve: function, reject: function, promise: Promise}>}
|
|
1158
1037
|
*/
|
|
1038
|
+
let promiseMap = {};
|
|
1159
1039
|
|
|
1160
|
-
var promiseMap = {};
|
|
1161
1040
|
/**
|
|
1162
1041
|
* Create an info object for a new promise in the map.
|
|
1163
1042
|
*
|
|
1164
1043
|
* @return {string} id of the promise
|
|
1165
1044
|
*/
|
|
1166
|
-
|
|
1167
1045
|
function createPromiseObject() {
|
|
1168
|
-
|
|
1046
|
+
const id = genID();
|
|
1169
1047
|
|
|
1048
|
+
// When the id is already used, it invokes the function again
|
|
1170
1049
|
if (id in promiseMap) return createPromiseObject();
|
|
1171
1050
|
promiseMap[id] = {
|
|
1172
1051
|
resolve: null,
|
|
@@ -1175,6 +1054,7 @@
|
|
|
1175
1054
|
};
|
|
1176
1055
|
return id;
|
|
1177
1056
|
}
|
|
1057
|
+
|
|
1178
1058
|
/**
|
|
1179
1059
|
* Create a promise and return it's id.
|
|
1180
1060
|
*
|
|
@@ -1182,17 +1062,16 @@
|
|
|
1182
1062
|
*
|
|
1183
1063
|
* @return {string} id of the promise
|
|
1184
1064
|
*/
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
var id = createPromiseObject();
|
|
1189
|
-
var p = new Promise(function (resolve, reject) {
|
|
1065
|
+
const create = () => {
|
|
1066
|
+
const id = createPromiseObject();
|
|
1067
|
+
const p = new Promise(function (resolve, reject) {
|
|
1190
1068
|
promiseMap[id].resolve = resolve;
|
|
1191
1069
|
promiseMap[id].reject = reject;
|
|
1192
1070
|
});
|
|
1193
1071
|
promiseMap[id].promise = p;
|
|
1194
1072
|
return id;
|
|
1195
1073
|
};
|
|
1074
|
+
|
|
1196
1075
|
/**
|
|
1197
1076
|
* Resolve a promise by id.
|
|
1198
1077
|
*
|
|
@@ -1201,12 +1080,12 @@
|
|
|
1201
1080
|
*
|
|
1202
1081
|
* @throws {Error} on unknown id
|
|
1203
1082
|
*/
|
|
1204
|
-
|
|
1205
|
-
var resolve = function resolve(id, msg) {
|
|
1083
|
+
const resolve = (id, msg) => {
|
|
1206
1084
|
if (!(id in promiseMap)) throw new Error('Tried to resolve an unknown [' + id + '] promise.');
|
|
1207
1085
|
promiseMap[id].resolve(msg);
|
|
1208
1086
|
delete promiseMap[id];
|
|
1209
1087
|
};
|
|
1088
|
+
|
|
1210
1089
|
/**
|
|
1211
1090
|
* Reject a promise by id.
|
|
1212
1091
|
*
|
|
@@ -1214,12 +1093,12 @@
|
|
|
1214
1093
|
* @param {any} err the error which will will be passed to reject
|
|
1215
1094
|
* @throws {Error} on unknown id
|
|
1216
1095
|
*/
|
|
1217
|
-
|
|
1218
|
-
var reject = function reject(id, err) {
|
|
1096
|
+
const reject = (id, err) => {
|
|
1219
1097
|
if (!(id in promiseMap)) throw new Error('Tried to reject an unknown [' + id + '] promise.');
|
|
1220
1098
|
promiseMap[id].reject(err);
|
|
1221
1099
|
delete promiseMap[id];
|
|
1222
1100
|
};
|
|
1101
|
+
|
|
1223
1102
|
/**
|
|
1224
1103
|
* Get a promise by id.
|
|
1225
1104
|
*
|
|
@@ -1227,8 +1106,7 @@
|
|
|
1227
1106
|
* @return {Promise} the promise identified by id
|
|
1228
1107
|
* @throws {Error} on unknown id
|
|
1229
1108
|
*/
|
|
1230
|
-
|
|
1231
|
-
var get = function get(id) {
|
|
1109
|
+
const get = id => {
|
|
1232
1110
|
if (!(id in promiseMap)) throw new Error('Tried to get an unknown [' + id + '] promise.');
|
|
1233
1111
|
return promiseMap[id].promise;
|
|
1234
1112
|
};
|
|
@@ -1251,10 +1129,11 @@
|
|
|
1251
1129
|
* @static
|
|
1252
1130
|
* @return {StaticValueStore}
|
|
1253
1131
|
*/
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1132
|
+
const dataStore$1 = _ref => {
|
|
1133
|
+
let {
|
|
1134
|
+
platform,
|
|
1135
|
+
language
|
|
1136
|
+
} = _ref;
|
|
1258
1137
|
return {
|
|
1259
1138
|
mobile: platform.mobile,
|
|
1260
1139
|
version: platform.version,
|
|
@@ -1265,22 +1144,20 @@
|
|
|
1265
1144
|
branchDefaultLanguage: language.branchDefaultLanguage
|
|
1266
1145
|
};
|
|
1267
1146
|
};
|
|
1147
|
+
let connection$1 = null;
|
|
1148
|
+
const targetOrigin = '*';
|
|
1268
1149
|
|
|
1269
|
-
var connection$1 = null;
|
|
1270
|
-
var targetOrigin = '*';
|
|
1271
1150
|
/**
|
|
1272
1151
|
* Connect to the Staffbase App.
|
|
1273
1152
|
*
|
|
1274
1153
|
* Create a connection to a Staffbase app 3.6
|
|
1275
1154
|
* @return {Promise<function>} An appropriate send function
|
|
1276
1155
|
*/
|
|
1277
|
-
|
|
1278
|
-
var connect$2 = function connect() {
|
|
1156
|
+
const connect$2 = () => {
|
|
1279
1157
|
if (connection$1) {
|
|
1280
1158
|
return connection$1;
|
|
1281
1159
|
}
|
|
1282
|
-
|
|
1283
|
-
var connectId = create();
|
|
1160
|
+
const connectId = create();
|
|
1284
1161
|
connection$1 = get(connectId).then(function (payload) {
|
|
1285
1162
|
return sendMessage$2(dataStore$1(payload));
|
|
1286
1163
|
});
|
|
@@ -1288,53 +1165,46 @@
|
|
|
1288
1165
|
window.parent.postMessage([protocol.HELLO, connectId, []], targetOrigin);
|
|
1289
1166
|
return connection$1;
|
|
1290
1167
|
};
|
|
1168
|
+
|
|
1291
1169
|
/**
|
|
1292
1170
|
* Handler that receives a message from the Staffbase app
|
|
1293
1171
|
*
|
|
1294
1172
|
* Can be attached to window.onPostMessage
|
|
1295
1173
|
* @param {MessageEvent} evt onPostMessage event result
|
|
1296
1174
|
*/
|
|
1175
|
+
const receiveMessage = async evt => {
|
|
1176
|
+
let type;
|
|
1177
|
+
let id;
|
|
1178
|
+
let payload;
|
|
1297
1179
|
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1180
|
+
// safe destructure
|
|
1181
|
+
try {
|
|
1182
|
+
({
|
|
1183
|
+
data: [type, id, payload]
|
|
1184
|
+
} = evt);
|
|
1185
|
+
} catch (e) {
|
|
1186
|
+
// even thought catch-ignore is a bad style
|
|
1187
|
+
// there may be other participants listening
|
|
1188
|
+
// to messages in a different format so we
|
|
1189
|
+
// silently ignore here
|
|
1190
|
+
return;
|
|
1191
|
+
}
|
|
1192
|
+
switch (type) {
|
|
1193
|
+
case protocol.SUCCESS:
|
|
1194
|
+
resolve(id, payload);
|
|
1195
|
+
break;
|
|
1196
|
+
case protocol.ERROR:
|
|
1197
|
+
reject(id, payload);
|
|
1198
|
+
break;
|
|
1199
|
+
default:
|
|
1311
1200
|
// even thought catch-ignore is a bad style
|
|
1312
1201
|
// there may be other participants listening
|
|
1313
1202
|
// to messages in a different format so we
|
|
1314
1203
|
// silently ignore here
|
|
1315
|
-
return
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
switch (type) {
|
|
1319
|
-
case protocol.SUCCESS:
|
|
1320
|
-
resolve(id, payload);
|
|
1321
|
-
break;
|
|
1322
|
-
|
|
1323
|
-
case protocol.ERROR:
|
|
1324
|
-
reject(id, payload);
|
|
1325
|
-
break;
|
|
1326
|
-
|
|
1327
|
-
default:
|
|
1328
|
-
// even thought catch-ignore is a bad style
|
|
1329
|
-
// there may be other participants listening
|
|
1330
|
-
// to messages in a different format so we
|
|
1331
|
-
// silently ignore here
|
|
1332
|
-
return $return();
|
|
1333
|
-
}
|
|
1334
|
-
|
|
1335
|
-
return $return();
|
|
1336
|
-
});
|
|
1204
|
+
return;
|
|
1205
|
+
}
|
|
1337
1206
|
};
|
|
1207
|
+
|
|
1338
1208
|
/**
|
|
1339
1209
|
* Send a SDK command to the Staffbase App.
|
|
1340
1210
|
*
|
|
@@ -1345,40 +1215,29 @@
|
|
|
1345
1215
|
* @return {Promise<any>} which awaits the response of the Staffbase App
|
|
1346
1216
|
* @throws {Error} on commands not supported by protocol
|
|
1347
1217
|
*/
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
case commands.openLink:
|
|
1365
|
-
case commands.nativeUpload:
|
|
1366
|
-
case commands.nativeShare:
|
|
1367
|
-
case commands.prefContentLang:
|
|
1368
|
-
for (var _len = $args.length, payload = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
1369
|
-
payload[_key - 1] = $args[_key];
|
|
1370
|
-
}
|
|
1371
|
-
|
|
1372
|
-
return $return(sendInvocationCall$1(create())(invocationMapping[cmd], payload));
|
|
1373
|
-
|
|
1374
|
-
default:
|
|
1375
|
-
return $error(new Error('Command ' + cmd + ' not supported by driver'));
|
|
1218
|
+
const sendMessage$2 = store => async function (cmd) {
|
|
1219
|
+
switch (cmd) {
|
|
1220
|
+
case commands.version:
|
|
1221
|
+
case commands.native:
|
|
1222
|
+
case commands.mobile:
|
|
1223
|
+
case commands.ios:
|
|
1224
|
+
case commands.android:
|
|
1225
|
+
case commands.branchDefaultLang:
|
|
1226
|
+
return store[reversedCommands[cmd]];
|
|
1227
|
+
case commands.langInfos:
|
|
1228
|
+
case commands.openLink:
|
|
1229
|
+
case commands.nativeUpload:
|
|
1230
|
+
case commands.nativeShare:
|
|
1231
|
+
case commands.prefContentLang:
|
|
1232
|
+
for (var _len = arguments.length, payload = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
1233
|
+
payload[_key - 1] = arguments[_key];
|
|
1376
1234
|
}
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
}
|
|
1235
|
+
return sendInvocationCall$1(create())(invocationMapping[cmd], payload);
|
|
1236
|
+
default:
|
|
1237
|
+
throw new Error('Command ' + cmd + ' not supported by driver');
|
|
1238
|
+
}
|
|
1381
1239
|
};
|
|
1240
|
+
|
|
1382
1241
|
/**
|
|
1383
1242
|
* Create a promise and send an invocation call to the frontend
|
|
1384
1243
|
*
|
|
@@ -1388,17 +1247,14 @@
|
|
|
1388
1247
|
*
|
|
1389
1248
|
* @return {Promise}
|
|
1390
1249
|
*/
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
return function (process, args) {
|
|
1395
|
-
window.parent.postMessage([protocol.INVOCATION, promiseID, process, args], targetOrigin);
|
|
1396
|
-
return get(promiseID);
|
|
1397
|
-
};
|
|
1250
|
+
const sendInvocationCall$1 = promiseID => (process, args) => {
|
|
1251
|
+
window.parent.postMessage([protocol.INVOCATION, promiseID, process, args], targetOrigin);
|
|
1252
|
+
return get(promiseID);
|
|
1398
1253
|
};
|
|
1399
1254
|
|
|
1400
|
-
|
|
1401
|
-
|
|
1255
|
+
let connection = null;
|
|
1256
|
+
let outMsgQueue = [];
|
|
1257
|
+
|
|
1402
1258
|
/**
|
|
1403
1259
|
* Simple store solution to make the initial data available
|
|
1404
1260
|
* as static values
|
|
@@ -1407,10 +1263,11 @@
|
|
|
1407
1263
|
* @static
|
|
1408
1264
|
* @return {StaticValueStore}
|
|
1409
1265
|
*/
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1266
|
+
const dataStore = _ref => {
|
|
1267
|
+
let {
|
|
1268
|
+
platform,
|
|
1269
|
+
language
|
|
1270
|
+
} = _ref;
|
|
1414
1271
|
return {
|
|
1415
1272
|
mobile: platform.mobile,
|
|
1416
1273
|
version: platform.version,
|
|
@@ -1421,31 +1278,30 @@
|
|
|
1421
1278
|
branchDefaultLang: language.branchDefaultLanguage
|
|
1422
1279
|
};
|
|
1423
1280
|
};
|
|
1424
|
-
|
|
1425
1281
|
window.Staffbase = window.Staffbase || {};
|
|
1426
1282
|
window.Staffbase.plugins = {
|
|
1427
1283
|
getMessages: multiMessageProvider,
|
|
1428
1284
|
putMessage: singleMessageReceiver
|
|
1429
1285
|
};
|
|
1286
|
+
|
|
1430
1287
|
/**
|
|
1431
1288
|
* Connect to the Staffbase App.
|
|
1432
1289
|
*
|
|
1433
1290
|
* Create a connection to a Staffbase app 3.6 from a native tab
|
|
1434
1291
|
* @return {Promise<function>} An appropriate send function
|
|
1435
1292
|
*/
|
|
1436
|
-
|
|
1437
|
-
var connect$1 = function connect() {
|
|
1293
|
+
const connect$1 = () => {
|
|
1438
1294
|
if (connection) {
|
|
1439
1295
|
return connection;
|
|
1440
1296
|
}
|
|
1441
|
-
|
|
1442
|
-
var connectId = create();
|
|
1297
|
+
const connectId = create();
|
|
1443
1298
|
connection = get(connectId).then(function (payload) {
|
|
1444
1299
|
return sendMessage$1(dataStore(payload));
|
|
1445
1300
|
});
|
|
1446
1301
|
outMsgQueue.push([protocol.HELLO, connectId, []]);
|
|
1447
1302
|
return connection;
|
|
1448
1303
|
};
|
|
1304
|
+
|
|
1449
1305
|
/**
|
|
1450
1306
|
* A function which returns an array of messages
|
|
1451
1307
|
*
|
|
@@ -1454,44 +1310,34 @@
|
|
|
1454
1310
|
*
|
|
1455
1311
|
* @return {Array} ordered list of messages
|
|
1456
1312
|
*/
|
|
1457
|
-
|
|
1458
1313
|
function multiMessageProvider() {
|
|
1459
|
-
|
|
1460
|
-
|
|
1314
|
+
const queueRef = outMsgQueue;
|
|
1461
1315
|
if (queueRef.length) ;
|
|
1462
|
-
|
|
1463
1316
|
outMsgQueue = [];
|
|
1464
1317
|
return queueRef;
|
|
1465
1318
|
}
|
|
1319
|
+
|
|
1466
1320
|
/**
|
|
1467
1321
|
* A function which can receive a single message.
|
|
1468
1322
|
*
|
|
1469
1323
|
* Can be attached to window.onPostMessage
|
|
1470
1324
|
* @param {Array} msg Staffbase 3.6 message
|
|
1471
1325
|
*/
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
1326
|
function singleMessageReceiver(msg) {
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1327
|
+
let type;
|
|
1328
|
+
let id;
|
|
1329
|
+
let payload;
|
|
1478
1330
|
|
|
1331
|
+
// safe destructure
|
|
1479
1332
|
try {
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
type = _msg[0];
|
|
1483
|
-
id = _msg[1];
|
|
1484
|
-
payload = _msg[2];
|
|
1485
|
-
|
|
1333
|
+
[type, id, payload] = msg;
|
|
1486
1334
|
switch (type) {
|
|
1487
1335
|
case protocol.SUCCESS:
|
|
1488
1336
|
resolve(id, payload);
|
|
1489
1337
|
break;
|
|
1490
|
-
|
|
1491
1338
|
case protocol.ERROR:
|
|
1492
1339
|
reject(id, payload);
|
|
1493
1340
|
break;
|
|
1494
|
-
|
|
1495
1341
|
default:
|
|
1496
1342
|
// even thought catch-ignore is a bad style
|
|
1497
1343
|
// there may be other participants listening
|
|
@@ -1507,6 +1353,7 @@
|
|
|
1507
1353
|
return;
|
|
1508
1354
|
}
|
|
1509
1355
|
}
|
|
1356
|
+
|
|
1510
1357
|
/**
|
|
1511
1358
|
* Send a SDK command to the Staffbase App.
|
|
1512
1359
|
*
|
|
@@ -1517,37 +1364,27 @@
|
|
|
1517
1364
|
* @return {Promise<any>} which awaits the response of the Staffbase App
|
|
1518
1365
|
* @throws {Error} on commands not supported by protocol
|
|
1519
1366
|
*/
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
case commands.openLink:
|
|
1536
|
-
case commands.prefContentLang:
|
|
1537
|
-
for (var _len = $args.length, payload = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
1538
|
-
payload[_key - 1] = $args[_key];
|
|
1539
|
-
}
|
|
1540
|
-
|
|
1541
|
-
return $return(sendInvocationCall(invocationMapping[cmd], payload));
|
|
1542
|
-
|
|
1543
|
-
default:
|
|
1544
|
-
return $error(new Error('Command ' + cmd + ' not supported by driver'));
|
|
1367
|
+
const sendMessage$1 = store => async function (cmd) {
|
|
1368
|
+
switch (cmd) {
|
|
1369
|
+
case commands.version:
|
|
1370
|
+
case commands.native:
|
|
1371
|
+
case commands.mobile:
|
|
1372
|
+
case commands.ios:
|
|
1373
|
+
case commands.android:
|
|
1374
|
+
case commands.langInfos:
|
|
1375
|
+
case commands.branchDefaultLang:
|
|
1376
|
+
return store[reversedCommands[cmd]];
|
|
1377
|
+
case commands.openLink:
|
|
1378
|
+
case commands.prefContentLang:
|
|
1379
|
+
for (var _len = arguments.length, payload = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
1380
|
+
payload[_key - 1] = arguments[_key];
|
|
1545
1381
|
}
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
}
|
|
1382
|
+
return sendInvocationCall(invocationMapping[cmd], payload);
|
|
1383
|
+
default:
|
|
1384
|
+
throw new Error('Command ' + cmd + ' not supported by driver');
|
|
1385
|
+
}
|
|
1550
1386
|
};
|
|
1387
|
+
|
|
1551
1388
|
/**
|
|
1552
1389
|
* Create a promise and send an invocation call to the frontend
|
|
1553
1390
|
*
|
|
@@ -1556,31 +1393,27 @@
|
|
|
1556
1393
|
*
|
|
1557
1394
|
* @return {Promise}
|
|
1558
1395
|
*/
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
var sendInvocationCall = function sendInvocationCall(process, args) {
|
|
1562
|
-
var promiseID = create();
|
|
1396
|
+
const sendInvocationCall = (process, args) => {
|
|
1397
|
+
const promiseID = create();
|
|
1563
1398
|
outMsgQueue.push([protocol.INVOCATION, promiseID, process, args]);
|
|
1564
1399
|
return get(promiseID);
|
|
1565
1400
|
};
|
|
1566
1401
|
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
Promise.race(realConnectionBucket).then(function (newConnector) {
|
|
1579
|
-
connector = newConnector;
|
|
1580
|
-
});
|
|
1581
|
-
return Promise.resolve(Promise.race(fallbackConnectionBucket)).then($return, $error);
|
|
1402
|
+
let connector;
|
|
1403
|
+
const connect = async () => {
|
|
1404
|
+
const putMessageConnection = connect$1();
|
|
1405
|
+
const postMessageConnection = connect$2();
|
|
1406
|
+
const fallbackConnection = fallback();
|
|
1407
|
+
const realConnectionBucket = [putMessageConnection, postMessageConnection];
|
|
1408
|
+
const fallbackConnectionBucket = realConnectionBucket.concat(fallbackConnection);
|
|
1409
|
+
|
|
1410
|
+
// Wait on the real communication and replace the connector with
|
|
1411
|
+
Promise.race(realConnectionBucket).then(newConnector => {
|
|
1412
|
+
connector = newConnector;
|
|
1582
1413
|
});
|
|
1414
|
+
return await Promise.race(fallbackConnectionBucket);
|
|
1583
1415
|
};
|
|
1416
|
+
|
|
1584
1417
|
/**
|
|
1585
1418
|
* Send a message to the App
|
|
1586
1419
|
*
|
|
@@ -1591,30 +1424,15 @@
|
|
|
1591
1424
|
* @param {any} payload that will be attached to the message
|
|
1592
1425
|
* @return {Promise<any>} result of the request
|
|
1593
1426
|
*/
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
return Promise.resolve(connector).then(function ($await_2) {
|
|
1605
|
-
try {
|
|
1606
|
-
sendFn = $await_2;
|
|
1607
|
-
|
|
1608
|
-
for (_len = $args.length, payload = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
1609
|
-
payload[_key - 1] = $args[_key];
|
|
1610
|
-
}
|
|
1611
|
-
|
|
1612
|
-
return $return(sendFn.apply(void 0, [msg].concat(payload)));
|
|
1613
|
-
} catch ($boundEx) {
|
|
1614
|
-
return $error($boundEx);
|
|
1615
|
-
}
|
|
1616
|
-
}, $error);
|
|
1617
|
-
});
|
|
1427
|
+
const sendMessage = async function (msg) {
|
|
1428
|
+
if (!connector) {
|
|
1429
|
+
connector = connect();
|
|
1430
|
+
}
|
|
1431
|
+
const sendFn = await connector;
|
|
1432
|
+
for (var _len = arguments.length, payload = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
1433
|
+
payload[_key - 1] = arguments[_key];
|
|
1434
|
+
}
|
|
1435
|
+
return sendFn(msg, ...payload);
|
|
1618
1436
|
};
|
|
1619
1437
|
|
|
1620
1438
|
/**
|
|
@@ -1622,34 +1440,28 @@
|
|
|
1622
1440
|
*
|
|
1623
1441
|
* @return {Promise<string>}
|
|
1624
1442
|
*/
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
return new Promise(function ($return, $error) {
|
|
1628
|
-
return $return(sendMessage(commands.version));
|
|
1629
|
-
});
|
|
1443
|
+
const getVersion = async () => {
|
|
1444
|
+
return sendMessage(commands.version);
|
|
1630
1445
|
};
|
|
1446
|
+
|
|
1631
1447
|
/**
|
|
1632
1448
|
* Check if app is native.
|
|
1633
1449
|
*
|
|
1634
1450
|
* @return {Promise<boolean>}
|
|
1635
1451
|
*/
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
return new Promise(function ($return, $error) {
|
|
1639
|
-
return $return(sendMessage(commands.native));
|
|
1640
|
-
});
|
|
1452
|
+
const isNative = async () => {
|
|
1453
|
+
return sendMessage(commands.native);
|
|
1641
1454
|
};
|
|
1455
|
+
|
|
1642
1456
|
/**
|
|
1643
1457
|
* Check if app is mobile.
|
|
1644
1458
|
*
|
|
1645
1459
|
* @return {Promise<boolean>}
|
|
1646
1460
|
*/
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
return new Promise(function ($return, $error) {
|
|
1650
|
-
return $return(sendMessage(commands.mobile));
|
|
1651
|
-
});
|
|
1461
|
+
const isMobile = async () => {
|
|
1462
|
+
return sendMessage(commands.mobile);
|
|
1652
1463
|
};
|
|
1464
|
+
|
|
1653
1465
|
/**
|
|
1654
1466
|
* Open a link through the app.
|
|
1655
1467
|
*
|
|
@@ -1660,12 +1472,10 @@
|
|
|
1660
1472
|
*
|
|
1661
1473
|
* @return {Promise<any>}
|
|
1662
1474
|
*/
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
return new Promise(function ($return, $error) {
|
|
1666
|
-
return $return(sendMessage(commands.openLink, url));
|
|
1667
|
-
});
|
|
1475
|
+
const openLink$1 = async url => {
|
|
1476
|
+
return sendMessage(commands.openLink, url);
|
|
1668
1477
|
};
|
|
1478
|
+
|
|
1669
1479
|
/**
|
|
1670
1480
|
* Open a link explicitly in the external browser.
|
|
1671
1481
|
*
|
|
@@ -1673,14 +1483,12 @@
|
|
|
1673
1483
|
*
|
|
1674
1484
|
* @return {Promise<any>}
|
|
1675
1485
|
*/
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
return $return(sendMessage(commands.openLink, url, {
|
|
1680
|
-
inAppBrowser: false
|
|
1681
|
-
}));
|
|
1486
|
+
const openLinkExternal$1 = async url => {
|
|
1487
|
+
return sendMessage(commands.openLink, url, {
|
|
1488
|
+
inAppBrowser: false
|
|
1682
1489
|
});
|
|
1683
1490
|
};
|
|
1491
|
+
|
|
1684
1492
|
/**
|
|
1685
1493
|
* Open a link explicitly in the internal browser.
|
|
1686
1494
|
*
|
|
@@ -1688,14 +1496,12 @@
|
|
|
1688
1496
|
*
|
|
1689
1497
|
* @return {Promise<any>}
|
|
1690
1498
|
*/
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
return $return(sendMessage(commands.openLink, url, {
|
|
1695
|
-
inAppBrowser: true
|
|
1696
|
-
}));
|
|
1499
|
+
const openLinkInternal$1 = async url => {
|
|
1500
|
+
return sendMessage(commands.openLink, url, {
|
|
1501
|
+
inAppBrowser: true
|
|
1697
1502
|
});
|
|
1698
1503
|
};
|
|
1504
|
+
|
|
1699
1505
|
/**
|
|
1700
1506
|
* Open a native file upload dialog on device which do not support it by default.
|
|
1701
1507
|
*
|
|
@@ -1703,12 +1509,10 @@
|
|
|
1703
1509
|
*
|
|
1704
1510
|
* @return {Promise<any>}
|
|
1705
1511
|
*/
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
return new Promise(function ($return, $error) {
|
|
1709
|
-
return $return(sendMessage(commands.nativeUpload));
|
|
1710
|
-
});
|
|
1512
|
+
const openNativeFileDialog = async () => {
|
|
1513
|
+
return sendMessage(commands.nativeUpload);
|
|
1711
1514
|
};
|
|
1515
|
+
|
|
1712
1516
|
/**
|
|
1713
1517
|
* Open a share dialog on native devices
|
|
1714
1518
|
*
|
|
@@ -1724,51 +1528,37 @@
|
|
|
1724
1528
|
*
|
|
1725
1529
|
* @return {Promise<string>}
|
|
1726
1530
|
*/
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
return new Promise(function ($return, $error) {
|
|
1730
|
-
return $return(sendMessage(commands.nativeShare, content));
|
|
1731
|
-
});
|
|
1531
|
+
const openNativeShareDialog$1 = async content => {
|
|
1532
|
+
return sendMessage(commands.nativeShare, content);
|
|
1732
1533
|
};
|
|
1534
|
+
|
|
1733
1535
|
/**
|
|
1734
1536
|
* Get the content languages configured for the branch.
|
|
1735
1537
|
*
|
|
1736
1538
|
* @return {Promise<Object>}
|
|
1737
1539
|
*/
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
return new Promise(function ($return, $error) {
|
|
1741
|
-
return $return(sendMessage(commands.langInfos).then(function (res) {
|
|
1742
|
-
return res.branchLanguages;
|
|
1743
|
-
}));
|
|
1744
|
-
});
|
|
1540
|
+
const getBranchLanguages$1 = async () => {
|
|
1541
|
+
return sendMessage(commands.langInfos).then(res => res.branchLanguages);
|
|
1745
1542
|
};
|
|
1543
|
+
|
|
1746
1544
|
/**
|
|
1747
1545
|
* Get the default content language configured for the branch.
|
|
1748
1546
|
*
|
|
1749
1547
|
* @return {Promise<Object>}
|
|
1750
1548
|
*/
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
return new Promise(function ($return, $error) {
|
|
1754
|
-
return $return(sendMessage(commands.langInfos).then(function (res) {
|
|
1755
|
-
return res.branchDefaultLanguage;
|
|
1756
|
-
}));
|
|
1757
|
-
});
|
|
1549
|
+
const getBranchDefaultLanguage$1 = async () => {
|
|
1550
|
+
return sendMessage(commands.langInfos).then(res => res.branchDefaultLanguage);
|
|
1758
1551
|
};
|
|
1552
|
+
|
|
1759
1553
|
/**
|
|
1760
1554
|
* Get all content languages supported by the Staffbase app.
|
|
1761
1555
|
*
|
|
1762
1556
|
* @return {Promise<Object>}
|
|
1763
1557
|
*/
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
return new Promise(function ($return, $error) {
|
|
1767
|
-
return $return(sendMessage(commands.langInfos).then(function (res) {
|
|
1768
|
-
return res.contentLanguages;
|
|
1769
|
-
}));
|
|
1770
|
-
});
|
|
1558
|
+
const getContentLanguages$1 = async () => {
|
|
1559
|
+
return sendMessage(commands.langInfos).then(res => res.contentLanguages);
|
|
1771
1560
|
};
|
|
1561
|
+
|
|
1772
1562
|
/**
|
|
1773
1563
|
* Gets the chosen language from a given content object
|
|
1774
1564
|
*
|
|
@@ -1780,89 +1570,53 @@
|
|
|
1780
1570
|
*
|
|
1781
1571
|
* @return {Promise<string>}
|
|
1782
1572
|
*/
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
return new Promise(function ($return, $error) {
|
|
1786
|
-
return $return(sendMessage(commands.prefContentLang, content));
|
|
1787
|
-
});
|
|
1573
|
+
const getPreferredContentLocale$1 = async content => {
|
|
1574
|
+
return sendMessage(commands.prefContentLang, content);
|
|
1788
1575
|
};
|
|
1789
1576
|
|
|
1790
|
-
|
|
1577
|
+
/**
|
|
1578
|
+
* Compare [semver](https://semver.org/) version strings to find greater, equal or lesser.
|
|
1579
|
+
* This library supports the full semver specification, including comparing versions with different number of digits like `1.0.0`, `1.0`, `1`, and pre-release versions like `1.0.0-alpha`.
|
|
1580
|
+
* @param v1 - First version to compare
|
|
1581
|
+
* @param v2 - Second version to compare
|
|
1582
|
+
* @returns Numeric value compatible with the [Array.sort(fn) interface](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Parameters).
|
|
1583
|
+
*/
|
|
1584
|
+
const compareVersions = (v1, v2) => {
|
|
1791
1585
|
// validate input and split into segments
|
|
1792
1586
|
const n1 = validateAndParse(v1);
|
|
1793
|
-
const n2 = validateAndParse(v2);
|
|
1794
|
-
|
|
1587
|
+
const n2 = validateAndParse(v2);
|
|
1588
|
+
// pop off the patch
|
|
1795
1589
|
const p1 = n1.pop();
|
|
1796
|
-
const p2 = n2.pop();
|
|
1797
|
-
|
|
1590
|
+
const p2 = n2.pop();
|
|
1591
|
+
// validate numbers
|
|
1798
1592
|
const r = compareSegments(n1, n2);
|
|
1799
|
-
if (r !== 0) return r;
|
|
1800
|
-
|
|
1593
|
+
if (r !== 0) return r;
|
|
1594
|
+
// validate pre-release
|
|
1801
1595
|
if (p1 && p2) {
|
|
1802
1596
|
return compareSegments(p1.split('.'), p2.split('.'));
|
|
1803
1597
|
} else if (p1 || p2) {
|
|
1804
1598
|
return p1 ? -1 : 1;
|
|
1805
1599
|
}
|
|
1806
|
-
|
|
1807
1600
|
return 0;
|
|
1808
|
-
}
|
|
1809
|
-
const validate = v => typeof v === 'string' && /^[v\d]/.test(v) && semver.test(v);
|
|
1810
|
-
const compare = (v1, v2, operator) => {
|
|
1811
|
-
// validate input operator
|
|
1812
|
-
assertValidOperator(operator); // since result of compareVersions can only be -1 or 0 or 1
|
|
1813
|
-
// a simple map can be used to replace switch
|
|
1814
|
-
|
|
1815
|
-
const res = compareVersions(v1, v2);
|
|
1816
|
-
return operatorResMap[operator].includes(res);
|
|
1817
1601
|
};
|
|
1818
|
-
const satisfies = (v, r) => {
|
|
1819
|
-
// if no range operator then "="
|
|
1820
|
-
const m = r.match(/^([<>=~^]+)/);
|
|
1821
|
-
const op = m ? m[1] : '='; // if gt/lt/eq then operator compare
|
|
1822
|
-
|
|
1823
|
-
if (op !== '^' && op !== '~') return compare(v, r, op); // else range of either "~" or "^" is assumed
|
|
1824
|
-
|
|
1825
|
-
const [v1, v2, v3] = validateAndParse(v);
|
|
1826
|
-
const [r1, r2, r3] = validateAndParse(r);
|
|
1827
|
-
if (compareStrings(v1, r1) !== 0) return false;
|
|
1828
|
-
|
|
1829
|
-
if (op === '^') {
|
|
1830
|
-
return compareSegments([v2, v3], [r2, r3]) >= 0;
|
|
1831
|
-
}
|
|
1832
|
-
|
|
1833
|
-
if (compareStrings(v2, r2) !== 0) return false;
|
|
1834
|
-
return compareStrings(v3, r3) >= 0;
|
|
1835
|
-
}; // export CJS style for parity
|
|
1836
|
-
|
|
1837
|
-
compareVersions.validate = validate;
|
|
1838
|
-
compareVersions.compare = compare;
|
|
1839
|
-
compareVersions.sastisfies = satisfies;
|
|
1840
1602
|
const semver = /^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i;
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
if (typeof v !== 'string') {
|
|
1603
|
+
const validateAndParse = version => {
|
|
1604
|
+
if (typeof version !== 'string') {
|
|
1844
1605
|
throw new TypeError('Invalid argument expected string');
|
|
1845
1606
|
}
|
|
1846
|
-
|
|
1847
|
-
const match = v.match(semver);
|
|
1848
|
-
|
|
1607
|
+
const match = version.match(semver);
|
|
1849
1608
|
if (!match) {
|
|
1850
|
-
throw new Error(`Invalid argument not valid semver ('${
|
|
1609
|
+
throw new Error(`Invalid argument not valid semver ('${version}' received)`);
|
|
1851
1610
|
}
|
|
1852
|
-
|
|
1853
1611
|
match.shift();
|
|
1854
1612
|
return match;
|
|
1855
1613
|
};
|
|
1856
|
-
|
|
1857
1614
|
const isWildcard = s => s === '*' || s === 'x' || s === 'X';
|
|
1858
|
-
|
|
1859
1615
|
const tryParse = v => {
|
|
1860
1616
|
const n = parseInt(v, 10);
|
|
1861
1617
|
return isNaN(n) ? v : n;
|
|
1862
1618
|
};
|
|
1863
|
-
|
|
1864
1619
|
const forceType = (a, b) => typeof a !== typeof b ? [String(a), String(b)] : [a, b];
|
|
1865
|
-
|
|
1866
1620
|
const compareStrings = (a, b) => {
|
|
1867
1621
|
if (isWildcard(a) || isWildcard(b)) return 0;
|
|
1868
1622
|
const [ap, bp] = forceType(tryParse(a), tryParse(b));
|
|
@@ -1870,152 +1624,97 @@
|
|
|
1870
1624
|
if (ap < bp) return -1;
|
|
1871
1625
|
return 0;
|
|
1872
1626
|
};
|
|
1873
|
-
|
|
1874
1627
|
const compareSegments = (a, b) => {
|
|
1875
1628
|
for (let i = 0; i < Math.max(a.length, b.length); i++) {
|
|
1876
|
-
const r = compareStrings(a[i] || 0, b[i] || 0);
|
|
1629
|
+
const r = compareStrings(a[i] || '0', b[i] || '0');
|
|
1877
1630
|
if (r !== 0) return r;
|
|
1878
1631
|
}
|
|
1879
|
-
|
|
1880
1632
|
return 0;
|
|
1881
1633
|
};
|
|
1882
1634
|
|
|
1883
|
-
|
|
1884
|
-
'>': [1],
|
|
1885
|
-
'>=': [0, 1],
|
|
1886
|
-
'=': [0],
|
|
1887
|
-
'<=': [-1, 0],
|
|
1888
|
-
'<': [-1]
|
|
1889
|
-
};
|
|
1890
|
-
const allowedOperators = Object.keys(operatorResMap);
|
|
1891
|
-
|
|
1892
|
-
const assertValidOperator = op => {
|
|
1893
|
-
if (typeof op !== 'string') {
|
|
1894
|
-
throw new TypeError(`Invalid operator type, expected string but got ${typeof op}`);
|
|
1895
|
-
}
|
|
1896
|
-
|
|
1897
|
-
if (allowedOperators.indexOf(op) === -1) {
|
|
1898
|
-
throw new Error(`Invalid operator, expected one of ${allowedOperators.join('|')}`);
|
|
1899
|
-
}
|
|
1900
|
-
};
|
|
1901
|
-
|
|
1635
|
+
/* eslint-disable no-unused-vars */
|
|
1902
1636
|
/**
|
|
1903
1637
|
* Check if device is using ios.
|
|
1904
1638
|
*
|
|
1905
1639
|
* @return {Promise<boolean>}
|
|
1906
1640
|
*/
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
return new Promise(function ($return, $error) {
|
|
1910
|
-
return $return(sendMessage(commands.ios));
|
|
1911
|
-
});
|
|
1641
|
+
const isIos = async () => {
|
|
1642
|
+
return sendMessage(commands.ios);
|
|
1912
1643
|
};
|
|
1644
|
+
|
|
1913
1645
|
/**
|
|
1914
1646
|
* Check if device is using android.
|
|
1915
1647
|
*
|
|
1916
1648
|
* @return {Promise<boolean>}
|
|
1917
1649
|
*/
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
return new Promise(function ($return, $error) {
|
|
1921
|
-
return $return(sendMessage(commands.android));
|
|
1922
|
-
});
|
|
1650
|
+
const isAndroid = async () => {
|
|
1651
|
+
return sendMessage(commands.android);
|
|
1923
1652
|
};
|
|
1653
|
+
|
|
1924
1654
|
/**
|
|
1925
1655
|
* Check if device is able to perform a download.
|
|
1926
1656
|
*
|
|
1927
1657
|
* @return {Promise<boolean>}
|
|
1928
1658
|
*/
|
|
1659
|
+
const canDownload = async () => {
|
|
1660
|
+
let [native, version, ios] = await Promise.all([isNative(), getVersion(), isIos()]);
|
|
1929
1661
|
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1662
|
+
// support any development versions like X.Y-dev for compare versions
|
|
1663
|
+
const dashIndex = version.indexOf('-');
|
|
1664
|
+
version = version.substring(0, dashIndex != -1 ? dashIndex : version.length);
|
|
1933
1665
|
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
version = version.substring(0, dashIndex != -1 ? dashIndex : version.length); // mobile ios devices can not download with an app version less than 3.5
|
|
1939
|
-
// but apps below 3.5 don't have the platform information from the frontend available
|
|
1940
|
-
// so we disable download for all native ios devices under these conditions
|
|
1941
|
-
|
|
1942
|
-
return $return(!(compareVersions(version, '3.5') < 0 && native && ios));
|
|
1943
|
-
} catch ($boundEx) {
|
|
1944
|
-
return $error($boundEx);
|
|
1945
|
-
}
|
|
1946
|
-
}, $error);
|
|
1947
|
-
});
|
|
1666
|
+
// mobile ios devices can not download with an app version less than 3.5
|
|
1667
|
+
// but apps below 3.5 don't have the platform information from the frontend available
|
|
1668
|
+
// so we disable download for all native ios devices under these conditions
|
|
1669
|
+
return !(compareVersions(version, '3.5') < 0 && native && ios);
|
|
1948
1670
|
};
|
|
1949
1671
|
|
|
1950
1672
|
/**
|
|
1951
1673
|
* Interface exports
|
|
1952
1674
|
*/
|
|
1675
|
+
|
|
1953
1676
|
/**
|
|
1954
1677
|
* Check if device is able to perform a download.
|
|
1955
1678
|
* @function
|
|
1956
1679
|
* @return {Promise<boolean>}
|
|
1957
1680
|
*/
|
|
1681
|
+
const deviceCanDownload = async () => canDownload();
|
|
1958
1682
|
|
|
1959
|
-
var deviceCanDownload = function deviceCanDownload() {
|
|
1960
|
-
return new Promise(function ($return, $error) {
|
|
1961
|
-
return $return(canDownload());
|
|
1962
|
-
});
|
|
1963
|
-
};
|
|
1964
1683
|
/**
|
|
1965
1684
|
* Check if device is using ios.
|
|
1966
1685
|
* @function
|
|
1967
1686
|
* @return {Promise<boolean>}
|
|
1968
1687
|
*/
|
|
1688
|
+
const isIosDevice = async () => isIos();
|
|
1969
1689
|
|
|
1970
|
-
var isIosDevice = function isIosDevice() {
|
|
1971
|
-
return new Promise(function ($return, $error) {
|
|
1972
|
-
return $return(isIos());
|
|
1973
|
-
});
|
|
1974
|
-
};
|
|
1975
1690
|
/**
|
|
1976
1691
|
* Check if device is using android.
|
|
1977
1692
|
* @function
|
|
1978
1693
|
* @return {Promise<boolean>}
|
|
1979
1694
|
*/
|
|
1695
|
+
const isAndroidDevice = async () => isAndroid();
|
|
1980
1696
|
|
|
1981
|
-
var isAndroidDevice = function isAndroidDevice() {
|
|
1982
|
-
return new Promise(function ($return, $error) {
|
|
1983
|
-
return $return(isAndroid());
|
|
1984
|
-
});
|
|
1985
|
-
};
|
|
1986
1697
|
/**
|
|
1987
1698
|
* Get the version of the Staffbase App.
|
|
1988
1699
|
* @function
|
|
1989
1700
|
* @return {Promise<string>}
|
|
1990
1701
|
*/
|
|
1702
|
+
const getAppVersion = async () => getVersion();
|
|
1991
1703
|
|
|
1992
|
-
var getAppVersion = function getAppVersion() {
|
|
1993
|
-
return new Promise(function ($return, $error) {
|
|
1994
|
-
return $return(getVersion());
|
|
1995
|
-
});
|
|
1996
|
-
};
|
|
1997
1704
|
/**
|
|
1998
1705
|
* Check if app is native.
|
|
1999
1706
|
* @function
|
|
2000
1707
|
* @return {Promise<boolean>}
|
|
2001
1708
|
*/
|
|
1709
|
+
const isNativeApp = async () => isNative();
|
|
2002
1710
|
|
|
2003
|
-
var isNativeApp = function isNativeApp() {
|
|
2004
|
-
return new Promise(function ($return, $error) {
|
|
2005
|
-
return $return(isNative());
|
|
2006
|
-
});
|
|
2007
|
-
};
|
|
2008
1711
|
/**
|
|
2009
1712
|
* Check if app is mobile.
|
|
2010
1713
|
* @function
|
|
2011
1714
|
* @return {Promise<boolean>}
|
|
2012
1715
|
*/
|
|
1716
|
+
const isMobileApp = async () => isMobile();
|
|
2013
1717
|
|
|
2014
|
-
var isMobileApp = function isMobileApp() {
|
|
2015
|
-
return new Promise(function ($return, $error) {
|
|
2016
|
-
return $return(isMobile());
|
|
2017
|
-
});
|
|
2018
|
-
};
|
|
2019
1718
|
/**
|
|
2020
1719
|
* Open a link through the app.
|
|
2021
1720
|
*
|
|
@@ -2026,12 +1725,8 @@
|
|
|
2026
1725
|
* @function
|
|
2027
1726
|
* @return {Promise<any>}
|
|
2028
1727
|
*/
|
|
1728
|
+
const openLink = async url => openLink$1(url);
|
|
2029
1729
|
|
|
2030
|
-
var openLink = function openLink(url) {
|
|
2031
|
-
return new Promise(function ($return, $error) {
|
|
2032
|
-
return $return(openLink$1(url));
|
|
2033
|
-
});
|
|
2034
|
-
};
|
|
2035
1730
|
/**
|
|
2036
1731
|
* Open a link explicitly in the external browser.
|
|
2037
1732
|
*
|
|
@@ -2039,12 +1734,8 @@
|
|
|
2039
1734
|
* @function
|
|
2040
1735
|
* @return {Promise<any>}
|
|
2041
1736
|
*/
|
|
1737
|
+
const openLinkExternal = async url => openLinkExternal$1(url);
|
|
2042
1738
|
|
|
2043
|
-
var openLinkExternal = function openLinkExternal(url) {
|
|
2044
|
-
return new Promise(function ($return, $error) {
|
|
2045
|
-
return $return(openLinkExternal$1(url));
|
|
2046
|
-
});
|
|
2047
|
-
};
|
|
2048
1739
|
/**
|
|
2049
1740
|
* Open a link explicitly in the internal browser.
|
|
2050
1741
|
*
|
|
@@ -2052,45 +1743,29 @@
|
|
|
2052
1743
|
* @function
|
|
2053
1744
|
* @return {Promise<any>}
|
|
2054
1745
|
*/
|
|
1746
|
+
const openLinkInternal = async url => openLinkInternal$1(url);
|
|
2055
1747
|
|
|
2056
|
-
var openLinkInternal = function openLinkInternal(url) {
|
|
2057
|
-
return new Promise(function ($return, $error) {
|
|
2058
|
-
return $return(openLinkInternal$1(url));
|
|
2059
|
-
});
|
|
2060
|
-
};
|
|
2061
1748
|
/**
|
|
2062
1749
|
* Get all enabled content languages configured in the app.
|
|
2063
1750
|
* @function
|
|
2064
1751
|
* @return {Promise<any>}
|
|
2065
1752
|
*/
|
|
1753
|
+
const getBranchLanguages = async () => getBranchLanguages$1();
|
|
2066
1754
|
|
|
2067
|
-
var getBranchLanguages = function getBranchLanguages() {
|
|
2068
|
-
return new Promise(function ($return, $error) {
|
|
2069
|
-
return $return(getBranchLanguages$1());
|
|
2070
|
-
});
|
|
2071
|
-
};
|
|
2072
1755
|
/**
|
|
2073
1756
|
* Get the default content language configured in the app.
|
|
2074
1757
|
* @function
|
|
2075
1758
|
* @return {Promise<any>}
|
|
2076
1759
|
*/
|
|
1760
|
+
const getBranchDefaultLanguage = async () => getBranchDefaultLanguage$1();
|
|
2077
1761
|
|
|
2078
|
-
var getBranchDefaultLanguage = function getBranchDefaultLanguage() {
|
|
2079
|
-
return new Promise(function ($return, $error) {
|
|
2080
|
-
return $return(getBranchDefaultLanguage$1());
|
|
2081
|
-
});
|
|
2082
|
-
};
|
|
2083
1762
|
/**
|
|
2084
1763
|
* Get all content languages supported by the app.
|
|
2085
1764
|
* @function
|
|
2086
1765
|
* @return {Promise<any>}
|
|
2087
1766
|
*/
|
|
1767
|
+
const getContentLanguages = async () => getContentLanguages$1();
|
|
2088
1768
|
|
|
2089
|
-
var getContentLanguages = function getContentLanguages() {
|
|
2090
|
-
return new Promise(function ($return, $error) {
|
|
2091
|
-
return $return(getContentLanguages$1());
|
|
2092
|
-
});
|
|
2093
|
-
};
|
|
2094
1769
|
/**
|
|
2095
1770
|
* Gets the chosen language from a given content object
|
|
2096
1771
|
*
|
|
@@ -2102,12 +1777,8 @@
|
|
|
2102
1777
|
* @function
|
|
2103
1778
|
* @return {Promise<string>}
|
|
2104
1779
|
*/
|
|
1780
|
+
const getPreferredContentLocale = async content => getPreferredContentLocale$1(content);
|
|
2105
1781
|
|
|
2106
|
-
var getPreferredContentLocale = function getPreferredContentLocale(content) {
|
|
2107
|
-
return new Promise(function ($return, $error) {
|
|
2108
|
-
return $return(getPreferredContentLocale$1(content));
|
|
2109
|
-
});
|
|
2110
|
-
};
|
|
2111
1782
|
/**
|
|
2112
1783
|
* Open a share dialog on native devices
|
|
2113
1784
|
*
|
|
@@ -2123,13 +1794,8 @@
|
|
|
2123
1794
|
*
|
|
2124
1795
|
* @return {Promise<string>}
|
|
2125
1796
|
*/
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
return new Promise(function ($return, $error) {
|
|
2129
|
-
return $return(openNativeShareDialog$1(content));
|
|
2130
|
-
});
|
|
2131
|
-
};
|
|
2132
|
-
/* experimental */
|
|
1797
|
+
const openNativeShareDialog = async content => openNativeShareDialog$1(content);
|
|
1798
|
+
/* experimental */
|
|
2133
1799
|
|
|
2134
1800
|
exports.deviceCanDownload = deviceCanDownload;
|
|
2135
1801
|
exports.getAppVersion = getAppVersion;
|
|
@@ -2147,7 +1813,5 @@
|
|
|
2147
1813
|
exports.openNativeFileDialog = openNativeFileDialog;
|
|
2148
1814
|
exports.openNativeShareDialog = openNativeShareDialog;
|
|
2149
1815
|
|
|
2150
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2151
|
-
|
|
2152
1816
|
}));
|
|
2153
1817
|
//# sourceMappingURL=plugins-client-sdk.umd.js.map
|