@staffbase/plugins-client-sdk 1.2.2 → 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/README.md +14 -0
- package/dist/plugins-client-sdk.esm.js +646 -750
- package/dist/plugins-client-sdk.esm.js.map +1 -1
- package/dist/plugins-client-sdk.js +646 -752
- package/dist/plugins-client-sdk.js.map +1 -1
- package/dist/plugins-client-sdk.umd.js +646 -752
- 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 +37 -42
|
@@ -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,209 +351,439 @@
|
|
|
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 = {
|
|
363
|
+
af: {
|
|
364
|
+
key: 'af',
|
|
365
|
+
locale: 'af_ZA',
|
|
366
|
+
name: 'Afrikaans',
|
|
367
|
+
localizedName: 'Afrikaans'
|
|
368
|
+
},
|
|
369
|
+
am: {
|
|
370
|
+
key: 'am',
|
|
371
|
+
locale: 'am_ET',
|
|
372
|
+
name: 'አማርኛ',
|
|
373
|
+
localizedName: 'Amharic'
|
|
374
|
+
},
|
|
466
375
|
ar: {
|
|
467
376
|
key: 'ar',
|
|
377
|
+
locale: 'ar_SA',
|
|
378
|
+
name: 'العربية (المملكة العربية السعودية)',
|
|
379
|
+
direction: 'rtl',
|
|
380
|
+
localizedName: 'Arabic (Saudi Arabia)'
|
|
381
|
+
},
|
|
382
|
+
arAE: {
|
|
383
|
+
key: 'arAE',
|
|
468
384
|
locale: 'ar_AE',
|
|
469
|
-
name: 'العربية'
|
|
385
|
+
name: 'العربية (الإمارات العربية المتحدة)',
|
|
386
|
+
direction: 'rtl',
|
|
387
|
+
localizedName: 'Arabic (United Arab Emirates)'
|
|
388
|
+
},
|
|
389
|
+
arEG: {
|
|
390
|
+
key: 'arEG',
|
|
391
|
+
locale: 'ar_EG',
|
|
392
|
+
name: 'العربية (مصر)',
|
|
393
|
+
direction: 'rtl',
|
|
394
|
+
localizedName: 'Arabic (Egypt)'
|
|
470
395
|
},
|
|
471
396
|
bg: {
|
|
472
397
|
key: 'bg',
|
|
473
398
|
locale: 'bg_BG',
|
|
474
|
-
name: 'български'
|
|
399
|
+
name: 'български',
|
|
400
|
+
localizedName: 'Bulgarian'
|
|
475
401
|
},
|
|
476
402
|
bn: {
|
|
477
403
|
key: 'bn',
|
|
478
404
|
locale: 'bn_BD',
|
|
479
|
-
name: 'বাংলা'
|
|
405
|
+
name: 'বাংলা',
|
|
406
|
+
localizedName: 'Bengali'
|
|
407
|
+
},
|
|
408
|
+
bs: {
|
|
409
|
+
key: 'bs',
|
|
410
|
+
locale: 'bs_BA',
|
|
411
|
+
name: 'Bosanski',
|
|
412
|
+
localizedName: 'Bosnian'
|
|
480
413
|
},
|
|
481
414
|
cs: {
|
|
482
415
|
key: 'cs',
|
|
483
416
|
locale: 'cs_CZ',
|
|
484
|
-
name: 'Čeština'
|
|
417
|
+
name: 'Čeština',
|
|
418
|
+
localizedName: 'Czech'
|
|
419
|
+
},
|
|
420
|
+
cy: {
|
|
421
|
+
key: 'cy',
|
|
422
|
+
locale: 'cy_GB',
|
|
423
|
+
name: 'Cymraeg',
|
|
424
|
+
localizedName: 'Welsh'
|
|
485
425
|
},
|
|
486
426
|
da: {
|
|
487
427
|
key: 'da',
|
|
488
428
|
locale: 'da_DK',
|
|
489
|
-
name: 'Dansk'
|
|
429
|
+
name: 'Dansk',
|
|
430
|
+
localizedName: 'Danish'
|
|
490
431
|
},
|
|
491
432
|
de: {
|
|
492
433
|
key: 'de',
|
|
493
434
|
locale: 'de_DE',
|
|
494
|
-
name: 'Deutsch'
|
|
435
|
+
name: 'Deutsch',
|
|
436
|
+
localizedName: 'German'
|
|
495
437
|
},
|
|
496
438
|
el: {
|
|
497
439
|
key: 'el',
|
|
498
440
|
locale: 'el_GR',
|
|
499
|
-
name: 'Ελληνικά'
|
|
441
|
+
name: 'Ελληνικά',
|
|
442
|
+
localizedName: 'Greek'
|
|
500
443
|
},
|
|
501
444
|
en: {
|
|
502
445
|
key: 'en',
|
|
503
446
|
locale: 'en_US',
|
|
504
|
-
name: 'English'
|
|
447
|
+
name: 'English',
|
|
448
|
+
localizedName: 'English'
|
|
505
449
|
},
|
|
506
450
|
es: {
|
|
507
451
|
key: 'es',
|
|
508
452
|
locale: 'es_ES',
|
|
509
|
-
name: 'Español'
|
|
453
|
+
name: 'Español (España)',
|
|
454
|
+
localizedName: 'Spanish (Spain)'
|
|
455
|
+
},
|
|
456
|
+
esMX: {
|
|
457
|
+
key: 'esMX',
|
|
458
|
+
locale: 'es_MX',
|
|
459
|
+
name: 'Español (México)',
|
|
460
|
+
localizedName: 'Spanish (Mexico)'
|
|
510
461
|
},
|
|
511
462
|
et: {
|
|
512
463
|
key: 'et',
|
|
513
464
|
locale: 'et_EE',
|
|
514
|
-
name: 'Eesti keel'
|
|
465
|
+
name: 'Eesti keel',
|
|
466
|
+
localizedName: 'Estonian'
|
|
515
467
|
},
|
|
516
468
|
fi: {
|
|
517
469
|
key: 'fi',
|
|
518
470
|
locale: 'fi_FI',
|
|
519
|
-
name: 'Suomi'
|
|
471
|
+
name: 'Suomi',
|
|
472
|
+
localizedName: 'Finnish'
|
|
520
473
|
},
|
|
521
474
|
fr: {
|
|
522
475
|
key: 'fr',
|
|
523
476
|
locale: 'fr_FR',
|
|
524
|
-
name: 'Français'
|
|
477
|
+
name: 'Français (France)',
|
|
478
|
+
localizedName: 'French (France)'
|
|
479
|
+
},
|
|
480
|
+
frCA: {
|
|
481
|
+
key: 'frCA',
|
|
482
|
+
locale: 'fr_CA',
|
|
483
|
+
name: 'Français (Canada)',
|
|
484
|
+
localizedName: 'French (Canada)'
|
|
525
485
|
},
|
|
526
486
|
he: {
|
|
527
487
|
key: 'he',
|
|
528
488
|
locale: 'he_IL',
|
|
529
|
-
name: 'עִבְרִית'
|
|
489
|
+
name: 'עִבְרִית',
|
|
490
|
+
direction: 'rtl',
|
|
491
|
+
localizedName: 'Hebrew'
|
|
530
492
|
},
|
|
531
493
|
hi: {
|
|
532
494
|
key: 'hi',
|
|
533
495
|
locale: 'hi_IN',
|
|
534
|
-
name: 'िन्दी'
|
|
496
|
+
name: 'िन्दी',
|
|
497
|
+
localizedName: 'Hindi'
|
|
498
|
+
},
|
|
499
|
+
hk: {
|
|
500
|
+
key: 'hk',
|
|
501
|
+
locale: 'zh_HK',
|
|
502
|
+
name: '繁體中文',
|
|
503
|
+
localizedName: 'Chinese traditional'
|
|
504
|
+
},
|
|
505
|
+
ht: {
|
|
506
|
+
key: 'ht',
|
|
507
|
+
locale: 'ht_HT',
|
|
508
|
+
name: 'kreyòl ayisyen',
|
|
509
|
+
localizedName: 'Haitian Creole'
|
|
535
510
|
},
|
|
536
511
|
hr: {
|
|
537
512
|
key: 'hr',
|
|
538
513
|
locale: 'hr_HR',
|
|
539
|
-
name: 'Hrvatski'
|
|
514
|
+
name: 'Hrvatski',
|
|
515
|
+
localizedName: 'Croatian'
|
|
540
516
|
},
|
|
541
517
|
hu: {
|
|
542
518
|
key: 'hu',
|
|
543
519
|
locale: 'hu_HU',
|
|
544
|
-
name: 'Magyar'
|
|
520
|
+
name: 'Magyar',
|
|
521
|
+
localizedName: 'Hungarian'
|
|
522
|
+
},
|
|
523
|
+
in: {
|
|
524
|
+
key: 'in',
|
|
525
|
+
locale: 'in_ID',
|
|
526
|
+
name: 'Bahasa Indonesia',
|
|
527
|
+
localizedName: 'Indonesian'
|
|
545
528
|
},
|
|
546
529
|
is: {
|
|
547
530
|
key: 'is',
|
|
548
531
|
locale: 'is_IS',
|
|
549
|
-
name: 'Íslenska'
|
|
532
|
+
name: 'Íslenska',
|
|
533
|
+
localizedName: 'Icelandic'
|
|
550
534
|
},
|
|
551
535
|
it: {
|
|
552
536
|
key: 'it',
|
|
553
537
|
locale: 'it_IT',
|
|
554
|
-
name: 'Italiano'
|
|
538
|
+
name: 'Italiano',
|
|
539
|
+
localizedName: 'Italian'
|
|
555
540
|
},
|
|
556
541
|
ja: {
|
|
557
542
|
key: 'ja',
|
|
558
543
|
locale: 'ja_JP',
|
|
559
|
-
name: '日本語'
|
|
544
|
+
name: '日本語',
|
|
545
|
+
localizedName: 'Japanese'
|
|
546
|
+
},
|
|
547
|
+
kl: {
|
|
548
|
+
key: 'kl',
|
|
549
|
+
locale: 'kl_GL',
|
|
550
|
+
name: 'Kalaallisut',
|
|
551
|
+
localizedName: 'Greenlandic'
|
|
552
|
+
},
|
|
553
|
+
km: {
|
|
554
|
+
key: 'km',
|
|
555
|
+
locale: 'km_KH',
|
|
556
|
+
name: 'ខ្មែរ',
|
|
557
|
+
localizedName: 'Khmer'
|
|
560
558
|
},
|
|
561
559
|
ko: {
|
|
562
560
|
key: 'ko',
|
|
563
561
|
locale: 'ko_KR',
|
|
564
|
-
name: '한국어'
|
|
562
|
+
name: '한국어',
|
|
563
|
+
localizedName: 'Korean'
|
|
564
|
+
},
|
|
565
|
+
lo: {
|
|
566
|
+
key: 'lo',
|
|
567
|
+
locale: 'lo_LA',
|
|
568
|
+
name: 'ລາວ',
|
|
569
|
+
localizedName: 'Lao'
|
|
565
570
|
},
|
|
566
571
|
lt: {
|
|
567
572
|
key: 'lt',
|
|
568
573
|
locale: 'lt_LT',
|
|
569
|
-
name: 'Lietuvių'
|
|
574
|
+
name: 'Lietuvių',
|
|
575
|
+
localizedName: 'Lithuanian'
|
|
570
576
|
},
|
|
571
577
|
lv: {
|
|
572
578
|
key: 'lv',
|
|
573
579
|
locale: 'lv_LV',
|
|
574
|
-
name: 'Latviešu'
|
|
580
|
+
name: 'Latviešu',
|
|
581
|
+
localizedName: 'Latvian'
|
|
582
|
+
},
|
|
583
|
+
mg: {
|
|
584
|
+
key: 'mg',
|
|
585
|
+
locale: 'mg_MG',
|
|
586
|
+
name: 'Malagasy',
|
|
587
|
+
localizedName: 'Malagasy'
|
|
575
588
|
},
|
|
576
589
|
mk: {
|
|
577
590
|
key: 'mk',
|
|
578
591
|
locale: 'mk_MK',
|
|
579
|
-
name: 'Македонски'
|
|
592
|
+
name: 'Македонски',
|
|
593
|
+
localizedName: 'Macedonian'
|
|
594
|
+
},
|
|
595
|
+
mh: {
|
|
596
|
+
key: 'mh',
|
|
597
|
+
locale: 'mh_MH',
|
|
598
|
+
name: 'Kajin M̧ajeļ',
|
|
599
|
+
localizedName: 'Marshallese'
|
|
600
|
+
},
|
|
601
|
+
mi: {
|
|
602
|
+
key: 'mi',
|
|
603
|
+
locale: 'mi_NZ',
|
|
604
|
+
name: 'Māori',
|
|
605
|
+
localizedName: 'Māori'
|
|
606
|
+
},
|
|
607
|
+
mn: {
|
|
608
|
+
key: 'mn',
|
|
609
|
+
locale: 'mn_MN',
|
|
610
|
+
name: 'монгол',
|
|
611
|
+
localizedName: 'Mongolian'
|
|
612
|
+
},
|
|
613
|
+
mr: {
|
|
614
|
+
key: 'mr',
|
|
615
|
+
locale: 'mr_IN',
|
|
616
|
+
name: 'मराठी',
|
|
617
|
+
localizedName: 'Marathi'
|
|
580
618
|
},
|
|
581
619
|
ms: {
|
|
582
620
|
key: 'ms',
|
|
583
621
|
locale: 'ms_MY',
|
|
584
|
-
name: 'Bahasa Melayu'
|
|
622
|
+
name: 'Bahasa Melayu',
|
|
623
|
+
localizedName: 'Malay'
|
|
624
|
+
},
|
|
625
|
+
my: {
|
|
626
|
+
key: 'my',
|
|
627
|
+
locale: 'my_MM',
|
|
628
|
+
name: 'Burmese',
|
|
629
|
+
localizedName: 'Burmese'
|
|
630
|
+
},
|
|
631
|
+
ne: {
|
|
632
|
+
key: 'ne',
|
|
633
|
+
locale: 'ne_NP',
|
|
634
|
+
name: 'नेपाली',
|
|
635
|
+
localizedName: 'Nepali'
|
|
585
636
|
},
|
|
586
637
|
nl: {
|
|
587
638
|
key: 'nl',
|
|
588
639
|
locale: 'nl_NL',
|
|
589
|
-
name: 'Nederlands'
|
|
640
|
+
name: 'Nederlands',
|
|
641
|
+
localizedName: 'Dutch'
|
|
642
|
+
},
|
|
643
|
+
nlBE: {
|
|
644
|
+
key: 'nlBE',
|
|
645
|
+
locale: 'nl_BE',
|
|
646
|
+
name: 'Vlaemsch',
|
|
647
|
+
localizedName: 'Flemish'
|
|
590
648
|
},
|
|
591
649
|
no: {
|
|
592
650
|
key: 'no',
|
|
593
651
|
locale: 'no_NO',
|
|
594
|
-
name: 'Norsk'
|
|
652
|
+
name: 'Norsk',
|
|
653
|
+
localizedName: 'Norwegian'
|
|
595
654
|
},
|
|
596
655
|
pl: {
|
|
597
656
|
key: 'pl',
|
|
598
657
|
locale: 'pl_PL',
|
|
599
|
-
name: 'Polski'
|
|
658
|
+
name: 'Polski',
|
|
659
|
+
localizedName: 'Polish'
|
|
600
660
|
},
|
|
601
661
|
pt: {
|
|
602
662
|
key: 'pt',
|
|
663
|
+
locale: 'pt_PT',
|
|
664
|
+
name: 'Português (Portugal)',
|
|
665
|
+
localizedName: 'Portuguese (Portugal)'
|
|
666
|
+
},
|
|
667
|
+
ptBR: {
|
|
668
|
+
key: 'ptBR',
|
|
603
669
|
locale: 'pt_BR',
|
|
604
|
-
name: 'Português'
|
|
670
|
+
name: 'Português (Brasil)',
|
|
671
|
+
localizedName: 'Portuguese (Brazil)'
|
|
605
672
|
},
|
|
606
673
|
ro: {
|
|
607
674
|
key: 'ro',
|
|
608
675
|
locale: 'ro_RO',
|
|
609
|
-
name: 'Română'
|
|
676
|
+
name: 'Română',
|
|
677
|
+
localizedName: 'Romanian'
|
|
610
678
|
},
|
|
611
679
|
ru: {
|
|
612
680
|
key: 'ru',
|
|
613
681
|
locale: 'ru_RU',
|
|
614
|
-
name: 'Русский'
|
|
682
|
+
name: 'Русский',
|
|
683
|
+
localizedName: 'Russian'
|
|
684
|
+
},
|
|
685
|
+
si: {
|
|
686
|
+
key: 'si',
|
|
687
|
+
locale: 'si_LK',
|
|
688
|
+
name: 'සිංහල',
|
|
689
|
+
localizedName: 'Sinhala'
|
|
615
690
|
},
|
|
616
691
|
sk: {
|
|
617
692
|
key: 'sk',
|
|
618
693
|
locale: 'sk_SK',
|
|
619
|
-
name: 'Slovenský'
|
|
694
|
+
name: 'Slovenský',
|
|
695
|
+
localizedName: 'Slovak'
|
|
620
696
|
},
|
|
621
697
|
sl: {
|
|
622
698
|
key: 'sl',
|
|
623
699
|
locale: 'sl_SI',
|
|
624
|
-
name: 'Slovenščina'
|
|
700
|
+
name: 'Slovenščina',
|
|
701
|
+
localizedName: 'Slovenian'
|
|
702
|
+
},
|
|
703
|
+
sq: {
|
|
704
|
+
key: 'sq',
|
|
705
|
+
locale: 'sq_AL',
|
|
706
|
+
name: 'Shqip',
|
|
707
|
+
localizedName: 'Albanian'
|
|
625
708
|
},
|
|
626
709
|
sr: {
|
|
627
710
|
key: 'sr',
|
|
628
711
|
locale: 'sr_RS',
|
|
629
|
-
name: 'Српски'
|
|
712
|
+
name: 'Српски',
|
|
713
|
+
localizedName: 'Serbian'
|
|
714
|
+
},
|
|
715
|
+
so: {
|
|
716
|
+
key: 'so',
|
|
717
|
+
locale: 'so_SO',
|
|
718
|
+
name: 'Af-Soomaali',
|
|
719
|
+
localizedName: 'Somali'
|
|
630
720
|
},
|
|
631
721
|
sv: {
|
|
632
722
|
key: 'sv',
|
|
633
723
|
locale: 'sv_SE',
|
|
634
|
-
name: 'Svenska'
|
|
724
|
+
name: 'Svenska',
|
|
725
|
+
localizedName: 'Swedish'
|
|
726
|
+
},
|
|
727
|
+
sw: {
|
|
728
|
+
key: 'sw',
|
|
729
|
+
locale: 'sw_TZ',
|
|
730
|
+
name: 'Swahili',
|
|
731
|
+
localizedName: 'Swahili'
|
|
732
|
+
},
|
|
733
|
+
ta: {
|
|
734
|
+
key: 'ta',
|
|
735
|
+
locale: 'ta_IN',
|
|
736
|
+
name: 'தமிழ்',
|
|
737
|
+
localizedName: 'Tamil'
|
|
738
|
+
},
|
|
739
|
+
tl: {
|
|
740
|
+
key: 'tl',
|
|
741
|
+
locale: 'tl_PH',
|
|
742
|
+
name: 'Filipino',
|
|
743
|
+
localizedName: 'Filipino'
|
|
635
744
|
},
|
|
636
745
|
th: {
|
|
637
746
|
key: 'th',
|
|
638
747
|
locale: 'th_TH',
|
|
639
|
-
name: 'ภาษาไทย'
|
|
748
|
+
name: 'ภาษาไทย',
|
|
749
|
+
localizedName: 'Thai'
|
|
640
750
|
},
|
|
641
751
|
tr: {
|
|
642
752
|
key: 'tr',
|
|
643
753
|
locale: 'tr_TR',
|
|
644
|
-
name: 'Türkçe'
|
|
754
|
+
name: 'Türkçe',
|
|
755
|
+
localizedName: 'Turkish'
|
|
645
756
|
},
|
|
646
757
|
uk: {
|
|
647
758
|
key: 'uk',
|
|
648
759
|
locale: 'uk_UA',
|
|
649
|
-
name: 'Українська'
|
|
760
|
+
name: 'Українська',
|
|
761
|
+
localizedName: 'Ukrainian'
|
|
762
|
+
},
|
|
763
|
+
ur: {
|
|
764
|
+
key: 'ur',
|
|
765
|
+
locale: 'ur_PK',
|
|
766
|
+
name: 'اُردُو',
|
|
767
|
+
direction: 'rtl',
|
|
768
|
+
localizedName: 'Urdu'
|
|
650
769
|
},
|
|
651
770
|
vi: {
|
|
652
771
|
key: 'vi',
|
|
653
772
|
locale: 'vi_VN',
|
|
654
|
-
name: 'Tiếng Việt'
|
|
773
|
+
name: 'Tiếng Việt',
|
|
774
|
+
localizedName: 'Vietnamese'
|
|
655
775
|
},
|
|
656
776
|
zh: {
|
|
657
777
|
key: 'zh',
|
|
658
778
|
locale: 'zh_CN',
|
|
659
|
-
name: '简体中文'
|
|
779
|
+
name: '简体中文',
|
|
780
|
+
localizedName: 'Chinese'
|
|
781
|
+
},
|
|
782
|
+
zu: {
|
|
783
|
+
key: 'zu',
|
|
784
|
+
locale: 'zu_ZA',
|
|
785
|
+
name: 'isiZulu',
|
|
786
|
+
localizedName: 'Zulu'
|
|
660
787
|
}
|
|
661
788
|
};
|
|
662
789
|
|
|
@@ -667,29 +794,28 @@
|
|
|
667
794
|
*
|
|
668
795
|
* @return {string} the first part of the locale
|
|
669
796
|
*/
|
|
670
|
-
|
|
797
|
+
const normalize = locale => {
|
|
671
798
|
locale = locale && locale.split(/-|_/)[0] || locale; // use only first part
|
|
672
799
|
|
|
673
800
|
if (['nb', 'nn'].indexOf(locale) !== -1) {
|
|
674
801
|
// fix Norwegian language code to conform with our non-standard stuff
|
|
675
802
|
locale = 'no';
|
|
676
803
|
}
|
|
677
|
-
|
|
678
804
|
if (locale === 'iw') {
|
|
679
805
|
// fix legacy Hebrew language code from our backend to conform with our frontend
|
|
680
806
|
locale = 'he';
|
|
681
807
|
}
|
|
682
|
-
|
|
683
808
|
return locale;
|
|
684
809
|
};
|
|
685
810
|
|
|
686
811
|
/**
|
|
687
812
|
* Fallbacks for all sdk commands
|
|
688
813
|
*/
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
// 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);
|
|
692
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
|
|
693
819
|
if (typeof window !== 'undefined') {
|
|
694
820
|
window.Staffbase = window.Staffbase || {};
|
|
695
821
|
window.Staffbase.platform = window.Staffbase.platform || {
|
|
@@ -698,81 +824,80 @@
|
|
|
698
824
|
native: false
|
|
699
825
|
};
|
|
700
826
|
}
|
|
827
|
+
|
|
701
828
|
/**
|
|
702
829
|
* Get the current Staffbase app version
|
|
703
830
|
*
|
|
704
831
|
* @return {String} version
|
|
705
832
|
*/
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
var getVersion$1 = function getVersion() {
|
|
833
|
+
const getVersion$1 = () => {
|
|
709
834
|
return window.Staffbase.platform.version;
|
|
710
835
|
};
|
|
836
|
+
|
|
711
837
|
/**
|
|
712
838
|
* Are we running in a native app
|
|
713
839
|
*
|
|
714
840
|
* works only for ios or old initial native data
|
|
715
841
|
* @return {Boolean}
|
|
716
842
|
*/
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
var safari = /safari/i.test(userAgent);
|
|
843
|
+
const isNative$1 = () => {
|
|
844
|
+
const safari = /safari/i.test(userAgent);
|
|
720
845
|
return window.Staffbase.platform.native === 'android' || window.Staffbase.platform.native === 'ios' || !safari && isIos$1();
|
|
721
846
|
};
|
|
847
|
+
|
|
722
848
|
/**
|
|
723
849
|
* Are we running on a mobile device
|
|
724
850
|
*
|
|
725
851
|
* @return {Boolean}
|
|
726
852
|
*/
|
|
727
|
-
|
|
728
|
-
var isMobile$1 = function isMobile() {
|
|
853
|
+
const isMobile$1 = () => {
|
|
729
854
|
return window.Staffbase.platform.mobile;
|
|
730
855
|
};
|
|
856
|
+
|
|
731
857
|
/**
|
|
732
858
|
* Are we running on android
|
|
733
859
|
*
|
|
734
860
|
* @return {Boolean}
|
|
735
861
|
*/
|
|
736
|
-
|
|
737
|
-
var isAndroid$1 = function isAndroid() {
|
|
862
|
+
const isAndroid$1 = () => {
|
|
738
863
|
return window.Staffbase.platform.native === 'android' || /Android/i.test(userAgent);
|
|
739
864
|
};
|
|
865
|
+
|
|
740
866
|
/**
|
|
741
867
|
* Are we running on ios
|
|
742
868
|
*
|
|
743
869
|
* @return {Boolean}
|
|
744
870
|
*/
|
|
745
|
-
|
|
746
|
-
var isIos$1 = function isIos() {
|
|
871
|
+
const isIos$1 = () => {
|
|
747
872
|
return window.Staffbase.platform.native === 'ios' || /iPhone|iPad|iPod/i.test(userAgent);
|
|
748
873
|
};
|
|
874
|
+
|
|
749
875
|
/**
|
|
750
876
|
* Open an external link
|
|
751
877
|
*
|
|
752
878
|
* @param {String} url address
|
|
753
879
|
*/
|
|
754
|
-
|
|
755
|
-
var openLink$2 = function openLink(url) {
|
|
880
|
+
const openLink$2 = url => {
|
|
756
881
|
window.open(url, '_blank');
|
|
757
882
|
};
|
|
883
|
+
|
|
758
884
|
/**
|
|
759
885
|
* Handler for unpossible functions
|
|
760
886
|
*
|
|
761
887
|
* @param {String} cmd command name
|
|
762
888
|
*/
|
|
763
|
-
|
|
764
|
-
var unSupported = function unSupported(cmd) {
|
|
889
|
+
const unSupported = cmd => {
|
|
765
890
|
// nothing we can do here
|
|
766
891
|
return;
|
|
767
892
|
};
|
|
893
|
+
|
|
768
894
|
/**
|
|
769
895
|
* Get extensive locale information.
|
|
770
896
|
*
|
|
771
897
|
* @return {Object} containing various language informations
|
|
772
898
|
*/
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
var branchDefaultLanguage = getBranchDefaultLanguage$2();
|
|
899
|
+
const langInfos = () => {
|
|
900
|
+
const branchDefaultLanguage = getBranchDefaultLanguage$2();
|
|
776
901
|
return {
|
|
777
902
|
contentLanguage: branchDefaultLanguage,
|
|
778
903
|
branchLanguages: locales,
|
|
@@ -781,15 +906,16 @@
|
|
|
781
906
|
contentLanguages: locales
|
|
782
907
|
};
|
|
783
908
|
};
|
|
909
|
+
|
|
784
910
|
/**
|
|
785
911
|
* Get the default language object
|
|
786
912
|
*
|
|
787
913
|
* @return {Object} the language object
|
|
788
914
|
*/
|
|
789
|
-
|
|
790
|
-
var getBranchDefaultLanguage$2 = function getBranchDefaultLanguage() {
|
|
915
|
+
const getBranchDefaultLanguage$2 = () => {
|
|
791
916
|
return locales[currentLanguage] || locales.en;
|
|
792
917
|
};
|
|
918
|
+
|
|
793
919
|
/**
|
|
794
920
|
* Gets the chosen language from a given content object
|
|
795
921
|
*
|
|
@@ -797,28 +923,24 @@
|
|
|
797
923
|
*
|
|
798
924
|
* @return {string}
|
|
799
925
|
*/
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
var locale = getBranchDefaultLanguage$2().locale;
|
|
803
|
-
|
|
926
|
+
const getPreferredContentLocale$2 = content => {
|
|
927
|
+
const locale = getBranchDefaultLanguage$2().locale;
|
|
804
928
|
if (!content) {
|
|
805
929
|
return locale;
|
|
806
930
|
}
|
|
807
|
-
|
|
808
931
|
if (Array.isArray(content)) {
|
|
809
|
-
|
|
932
|
+
const index = content.indexOf(locale);
|
|
810
933
|
return content[index] || content[0];
|
|
811
934
|
} else {
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
return keys[_index] || keys[0];
|
|
935
|
+
const keys = Object.keys(content);
|
|
936
|
+
const index = keys.indexOf(locale);
|
|
937
|
+
return keys[index] || keys[0];
|
|
817
938
|
}
|
|
818
939
|
};
|
|
819
940
|
|
|
820
|
-
|
|
821
|
-
|
|
941
|
+
let connection$2 = null;
|
|
942
|
+
const fallbackKickIn = 500;
|
|
943
|
+
|
|
822
944
|
/**
|
|
823
945
|
* Fake connection to the Staffbase App after a period of time.
|
|
824
946
|
*
|
|
@@ -826,19 +948,18 @@
|
|
|
826
948
|
* after the time specified in fallbackKickIn runs out.
|
|
827
949
|
* @return {Promise<function>} An appropriate send function
|
|
828
950
|
*/
|
|
829
|
-
|
|
830
|
-
var fallback = (function () {
|
|
951
|
+
var fallback = (() => {
|
|
831
952
|
if (connection$2) {
|
|
832
953
|
return connection$2;
|
|
833
954
|
}
|
|
834
|
-
|
|
835
|
-
connection$2 = new Promise(function (resolve) {
|
|
955
|
+
connection$2 = new Promise(resolve => {
|
|
836
956
|
setTimeout(function () {
|
|
837
957
|
resolve(sendMessage$3);
|
|
838
958
|
}, fallbackKickIn);
|
|
839
959
|
});
|
|
840
960
|
return connection$2;
|
|
841
961
|
});
|
|
962
|
+
|
|
842
963
|
/**
|
|
843
964
|
* Send a SDK command to the Staffbase App.
|
|
844
965
|
*
|
|
@@ -848,56 +969,38 @@
|
|
|
848
969
|
* @return {Promise<any>} which awaits the response of the Staffbase App
|
|
849
970
|
* @throws {Error} on commands not supported by protocol
|
|
850
971
|
*/
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
case commands.branchDefaultLang:
|
|
882
|
-
return $return(getBranchDefaultLanguage$2());
|
|
883
|
-
|
|
884
|
-
case commands.prefContentLang:
|
|
885
|
-
return $return(getPreferredContentLocale$2.apply(null, payload));
|
|
886
|
-
|
|
887
|
-
case commands.nativeUpload:
|
|
888
|
-
case commands.nativeShare:
|
|
889
|
-
return $return(unSupported());
|
|
890
|
-
|
|
891
|
-
default:
|
|
892
|
-
// should actually never ever happen
|
|
893
|
-
return $error(new Error('Command ' + cmd + ' not supported by driver'));
|
|
894
|
-
}
|
|
895
|
-
|
|
896
|
-
return $return();
|
|
897
|
-
});
|
|
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
|
+
}
|
|
898
1002
|
};
|
|
899
1003
|
|
|
900
|
-
var _invocationMapping;
|
|
901
1004
|
/**
|
|
902
1005
|
* Postmessage protocol (3.6)
|
|
903
1006
|
*/
|
|
@@ -910,33 +1013,39 @@
|
|
|
910
1013
|
INVOCATION: 'INVOCATION',
|
|
911
1014
|
// send this to call a function in the frontend
|
|
912
1015
|
ERROR: 'ERROR' // receive this when something goes wrong
|
|
1016
|
+
};
|
|
913
1017
|
|
|
1018
|
+
const invocationMapping = {
|
|
1019
|
+
[commands.openLink]: 'openLink',
|
|
1020
|
+
[commands.nativeUpload]: 'nativeFileUpload',
|
|
1021
|
+
[commands.nativeShare]: 'nativeShareDialog',
|
|
1022
|
+
[commands.langInfos]: 'getPluginLanguageInfo',
|
|
1023
|
+
[commands.prefContentLang]: 'getPreferredContentLocale'
|
|
914
1024
|
};
|
|
915
|
-
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);
|
|
916
1025
|
|
|
917
1026
|
/**
|
|
918
1027
|
* Generates an unique id of 4 alpha numerical chars
|
|
919
1028
|
*
|
|
920
1029
|
* @return {string} unique id
|
|
921
1030
|
*/
|
|
922
|
-
|
|
1031
|
+
const genID = () => {
|
|
923
1032
|
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
|
|
924
1033
|
};
|
|
925
1034
|
|
|
926
1035
|
/**
|
|
927
1036
|
* @type {Object.<string, {resolve: function, reject: function, promise: Promise}>}
|
|
928
1037
|
*/
|
|
1038
|
+
let promiseMap = {};
|
|
929
1039
|
|
|
930
|
-
var promiseMap = {};
|
|
931
1040
|
/**
|
|
932
1041
|
* Create an info object for a new promise in the map.
|
|
933
1042
|
*
|
|
934
1043
|
* @return {string} id of the promise
|
|
935
1044
|
*/
|
|
936
|
-
|
|
937
1045
|
function createPromiseObject() {
|
|
938
|
-
|
|
1046
|
+
const id = genID();
|
|
939
1047
|
|
|
1048
|
+
// When the id is already used, it invokes the function again
|
|
940
1049
|
if (id in promiseMap) return createPromiseObject();
|
|
941
1050
|
promiseMap[id] = {
|
|
942
1051
|
resolve: null,
|
|
@@ -945,6 +1054,7 @@
|
|
|
945
1054
|
};
|
|
946
1055
|
return id;
|
|
947
1056
|
}
|
|
1057
|
+
|
|
948
1058
|
/**
|
|
949
1059
|
* Create a promise and return it's id.
|
|
950
1060
|
*
|
|
@@ -952,17 +1062,16 @@
|
|
|
952
1062
|
*
|
|
953
1063
|
* @return {string} id of the promise
|
|
954
1064
|
*/
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
var id = createPromiseObject();
|
|
959
|
-
var p = new Promise(function (resolve, reject) {
|
|
1065
|
+
const create = () => {
|
|
1066
|
+
const id = createPromiseObject();
|
|
1067
|
+
const p = new Promise(function (resolve, reject) {
|
|
960
1068
|
promiseMap[id].resolve = resolve;
|
|
961
1069
|
promiseMap[id].reject = reject;
|
|
962
1070
|
});
|
|
963
1071
|
promiseMap[id].promise = p;
|
|
964
1072
|
return id;
|
|
965
1073
|
};
|
|
1074
|
+
|
|
966
1075
|
/**
|
|
967
1076
|
* Resolve a promise by id.
|
|
968
1077
|
*
|
|
@@ -971,12 +1080,12 @@
|
|
|
971
1080
|
*
|
|
972
1081
|
* @throws {Error} on unknown id
|
|
973
1082
|
*/
|
|
974
|
-
|
|
975
|
-
var resolve = function resolve(id, msg) {
|
|
1083
|
+
const resolve = (id, msg) => {
|
|
976
1084
|
if (!(id in promiseMap)) throw new Error('Tried to resolve an unknown [' + id + '] promise.');
|
|
977
1085
|
promiseMap[id].resolve(msg);
|
|
978
1086
|
delete promiseMap[id];
|
|
979
1087
|
};
|
|
1088
|
+
|
|
980
1089
|
/**
|
|
981
1090
|
* Reject a promise by id.
|
|
982
1091
|
*
|
|
@@ -984,12 +1093,12 @@
|
|
|
984
1093
|
* @param {any} err the error which will will be passed to reject
|
|
985
1094
|
* @throws {Error} on unknown id
|
|
986
1095
|
*/
|
|
987
|
-
|
|
988
|
-
var reject = function reject(id, err) {
|
|
1096
|
+
const reject = (id, err) => {
|
|
989
1097
|
if (!(id in promiseMap)) throw new Error('Tried to reject an unknown [' + id + '] promise.');
|
|
990
1098
|
promiseMap[id].reject(err);
|
|
991
1099
|
delete promiseMap[id];
|
|
992
1100
|
};
|
|
1101
|
+
|
|
993
1102
|
/**
|
|
994
1103
|
* Get a promise by id.
|
|
995
1104
|
*
|
|
@@ -997,8 +1106,7 @@
|
|
|
997
1106
|
* @return {Promise} the promise identified by id
|
|
998
1107
|
* @throws {Error} on unknown id
|
|
999
1108
|
*/
|
|
1000
|
-
|
|
1001
|
-
var get = function get(id) {
|
|
1109
|
+
const get = id => {
|
|
1002
1110
|
if (!(id in promiseMap)) throw new Error('Tried to get an unknown [' + id + '] promise.');
|
|
1003
1111
|
return promiseMap[id].promise;
|
|
1004
1112
|
};
|
|
@@ -1021,10 +1129,11 @@
|
|
|
1021
1129
|
* @static
|
|
1022
1130
|
* @return {StaticValueStore}
|
|
1023
1131
|
*/
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1132
|
+
const dataStore$1 = _ref => {
|
|
1133
|
+
let {
|
|
1134
|
+
platform,
|
|
1135
|
+
language
|
|
1136
|
+
} = _ref;
|
|
1028
1137
|
return {
|
|
1029
1138
|
mobile: platform.mobile,
|
|
1030
1139
|
version: platform.version,
|
|
@@ -1035,22 +1144,20 @@
|
|
|
1035
1144
|
branchDefaultLanguage: language.branchDefaultLanguage
|
|
1036
1145
|
};
|
|
1037
1146
|
};
|
|
1147
|
+
let connection$1 = null;
|
|
1148
|
+
const targetOrigin = '*';
|
|
1038
1149
|
|
|
1039
|
-
var connection$1 = null;
|
|
1040
|
-
var targetOrigin = '*';
|
|
1041
1150
|
/**
|
|
1042
1151
|
* Connect to the Staffbase App.
|
|
1043
1152
|
*
|
|
1044
1153
|
* Create a connection to a Staffbase app 3.6
|
|
1045
1154
|
* @return {Promise<function>} An appropriate send function
|
|
1046
1155
|
*/
|
|
1047
|
-
|
|
1048
|
-
var connect$2 = function connect() {
|
|
1156
|
+
const connect$2 = () => {
|
|
1049
1157
|
if (connection$1) {
|
|
1050
1158
|
return connection$1;
|
|
1051
1159
|
}
|
|
1052
|
-
|
|
1053
|
-
var connectId = create();
|
|
1160
|
+
const connectId = create();
|
|
1054
1161
|
connection$1 = get(connectId).then(function (payload) {
|
|
1055
1162
|
return sendMessage$2(dataStore$1(payload));
|
|
1056
1163
|
});
|
|
@@ -1058,53 +1165,46 @@
|
|
|
1058
1165
|
window.parent.postMessage([protocol.HELLO, connectId, []], targetOrigin);
|
|
1059
1166
|
return connection$1;
|
|
1060
1167
|
};
|
|
1168
|
+
|
|
1061
1169
|
/**
|
|
1062
1170
|
* Handler that receives a message from the Staffbase app
|
|
1063
1171
|
*
|
|
1064
1172
|
* Can be attached to window.onPostMessage
|
|
1065
1173
|
* @param {MessageEvent} evt onPostMessage event result
|
|
1066
1174
|
*/
|
|
1175
|
+
const receiveMessage = async evt => {
|
|
1176
|
+
let type;
|
|
1177
|
+
let id;
|
|
1178
|
+
let payload;
|
|
1067
1179
|
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
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:
|
|
1081
1200
|
// even thought catch-ignore is a bad style
|
|
1082
1201
|
// there may be other participants listening
|
|
1083
1202
|
// to messages in a different format so we
|
|
1084
1203
|
// silently ignore here
|
|
1085
|
-
return
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
switch (type) {
|
|
1089
|
-
case protocol.SUCCESS:
|
|
1090
|
-
resolve(id, payload);
|
|
1091
|
-
break;
|
|
1092
|
-
|
|
1093
|
-
case protocol.ERROR:
|
|
1094
|
-
reject(id, payload);
|
|
1095
|
-
break;
|
|
1096
|
-
|
|
1097
|
-
default:
|
|
1098
|
-
// even thought catch-ignore is a bad style
|
|
1099
|
-
// there may be other participants listening
|
|
1100
|
-
// to messages in a different format so we
|
|
1101
|
-
// silently ignore here
|
|
1102
|
-
return $return();
|
|
1103
|
-
}
|
|
1104
|
-
|
|
1105
|
-
return $return();
|
|
1106
|
-
});
|
|
1204
|
+
return;
|
|
1205
|
+
}
|
|
1107
1206
|
};
|
|
1207
|
+
|
|
1108
1208
|
/**
|
|
1109
1209
|
* Send a SDK command to the Staffbase App.
|
|
1110
1210
|
*
|
|
@@ -1115,40 +1215,29 @@
|
|
|
1115
1215
|
* @return {Promise<any>} which awaits the response of the Staffbase App
|
|
1116
1216
|
* @throws {Error} on commands not supported by protocol
|
|
1117
1217
|
*/
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
case commands.openLink:
|
|
1135
|
-
case commands.nativeUpload:
|
|
1136
|
-
case commands.nativeShare:
|
|
1137
|
-
case commands.prefContentLang:
|
|
1138
|
-
for (var _len = $args.length, payload = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
1139
|
-
payload[_key - 1] = $args[_key];
|
|
1140
|
-
}
|
|
1141
|
-
|
|
1142
|
-
return $return(sendInvocationCall$1(create())(invocationMapping[cmd], payload));
|
|
1143
|
-
|
|
1144
|
-
default:
|
|
1145
|
-
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];
|
|
1146
1234
|
}
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
}
|
|
1235
|
+
return sendInvocationCall$1(create())(invocationMapping[cmd], payload);
|
|
1236
|
+
default:
|
|
1237
|
+
throw new Error('Command ' + cmd + ' not supported by driver');
|
|
1238
|
+
}
|
|
1151
1239
|
};
|
|
1240
|
+
|
|
1152
1241
|
/**
|
|
1153
1242
|
* Create a promise and send an invocation call to the frontend
|
|
1154
1243
|
*
|
|
@@ -1158,17 +1247,14 @@
|
|
|
1158
1247
|
*
|
|
1159
1248
|
* @return {Promise}
|
|
1160
1249
|
*/
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
return function (process, args) {
|
|
1165
|
-
window.parent.postMessage([protocol.INVOCATION, promiseID, process, args], targetOrigin);
|
|
1166
|
-
return get(promiseID);
|
|
1167
|
-
};
|
|
1250
|
+
const sendInvocationCall$1 = promiseID => (process, args) => {
|
|
1251
|
+
window.parent.postMessage([protocol.INVOCATION, promiseID, process, args], targetOrigin);
|
|
1252
|
+
return get(promiseID);
|
|
1168
1253
|
};
|
|
1169
1254
|
|
|
1170
|
-
|
|
1171
|
-
|
|
1255
|
+
let connection = null;
|
|
1256
|
+
let outMsgQueue = [];
|
|
1257
|
+
|
|
1172
1258
|
/**
|
|
1173
1259
|
* Simple store solution to make the initial data available
|
|
1174
1260
|
* as static values
|
|
@@ -1177,10 +1263,11 @@
|
|
|
1177
1263
|
* @static
|
|
1178
1264
|
* @return {StaticValueStore}
|
|
1179
1265
|
*/
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1266
|
+
const dataStore = _ref => {
|
|
1267
|
+
let {
|
|
1268
|
+
platform,
|
|
1269
|
+
language
|
|
1270
|
+
} = _ref;
|
|
1184
1271
|
return {
|
|
1185
1272
|
mobile: platform.mobile,
|
|
1186
1273
|
version: platform.version,
|
|
@@ -1191,31 +1278,30 @@
|
|
|
1191
1278
|
branchDefaultLang: language.branchDefaultLanguage
|
|
1192
1279
|
};
|
|
1193
1280
|
};
|
|
1194
|
-
|
|
1195
1281
|
window.Staffbase = window.Staffbase || {};
|
|
1196
1282
|
window.Staffbase.plugins = {
|
|
1197
1283
|
getMessages: multiMessageProvider,
|
|
1198
1284
|
putMessage: singleMessageReceiver
|
|
1199
1285
|
};
|
|
1286
|
+
|
|
1200
1287
|
/**
|
|
1201
1288
|
* Connect to the Staffbase App.
|
|
1202
1289
|
*
|
|
1203
1290
|
* Create a connection to a Staffbase app 3.6 from a native tab
|
|
1204
1291
|
* @return {Promise<function>} An appropriate send function
|
|
1205
1292
|
*/
|
|
1206
|
-
|
|
1207
|
-
var connect$1 = function connect() {
|
|
1293
|
+
const connect$1 = () => {
|
|
1208
1294
|
if (connection) {
|
|
1209
1295
|
return connection;
|
|
1210
1296
|
}
|
|
1211
|
-
|
|
1212
|
-
var connectId = create();
|
|
1297
|
+
const connectId = create();
|
|
1213
1298
|
connection = get(connectId).then(function (payload) {
|
|
1214
1299
|
return sendMessage$1(dataStore(payload));
|
|
1215
1300
|
});
|
|
1216
1301
|
outMsgQueue.push([protocol.HELLO, connectId, []]);
|
|
1217
1302
|
return connection;
|
|
1218
1303
|
};
|
|
1304
|
+
|
|
1219
1305
|
/**
|
|
1220
1306
|
* A function which returns an array of messages
|
|
1221
1307
|
*
|
|
@@ -1224,44 +1310,34 @@
|
|
|
1224
1310
|
*
|
|
1225
1311
|
* @return {Array} ordered list of messages
|
|
1226
1312
|
*/
|
|
1227
|
-
|
|
1228
1313
|
function multiMessageProvider() {
|
|
1229
|
-
|
|
1230
|
-
|
|
1314
|
+
const queueRef = outMsgQueue;
|
|
1231
1315
|
if (queueRef.length) ;
|
|
1232
|
-
|
|
1233
1316
|
outMsgQueue = [];
|
|
1234
1317
|
return queueRef;
|
|
1235
1318
|
}
|
|
1319
|
+
|
|
1236
1320
|
/**
|
|
1237
1321
|
* A function which can receive a single message.
|
|
1238
1322
|
*
|
|
1239
1323
|
* Can be attached to window.onPostMessage
|
|
1240
1324
|
* @param {Array} msg Staffbase 3.6 message
|
|
1241
1325
|
*/
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
1326
|
function singleMessageReceiver(msg) {
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1327
|
+
let type;
|
|
1328
|
+
let id;
|
|
1329
|
+
let payload;
|
|
1248
1330
|
|
|
1331
|
+
// safe destructure
|
|
1249
1332
|
try {
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
type = _msg[0];
|
|
1253
|
-
id = _msg[1];
|
|
1254
|
-
payload = _msg[2];
|
|
1255
|
-
|
|
1333
|
+
[type, id, payload] = msg;
|
|
1256
1334
|
switch (type) {
|
|
1257
1335
|
case protocol.SUCCESS:
|
|
1258
1336
|
resolve(id, payload);
|
|
1259
1337
|
break;
|
|
1260
|
-
|
|
1261
1338
|
case protocol.ERROR:
|
|
1262
1339
|
reject(id, payload);
|
|
1263
1340
|
break;
|
|
1264
|
-
|
|
1265
1341
|
default:
|
|
1266
1342
|
// even thought catch-ignore is a bad style
|
|
1267
1343
|
// there may be other participants listening
|
|
@@ -1277,6 +1353,7 @@
|
|
|
1277
1353
|
return;
|
|
1278
1354
|
}
|
|
1279
1355
|
}
|
|
1356
|
+
|
|
1280
1357
|
/**
|
|
1281
1358
|
* Send a SDK command to the Staffbase App.
|
|
1282
1359
|
*
|
|
@@ -1287,37 +1364,27 @@
|
|
|
1287
1364
|
* @return {Promise<any>} which awaits the response of the Staffbase App
|
|
1288
1365
|
* @throws {Error} on commands not supported by protocol
|
|
1289
1366
|
*/
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
case commands.openLink:
|
|
1306
|
-
case commands.prefContentLang:
|
|
1307
|
-
for (var _len = $args.length, payload = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
1308
|
-
payload[_key - 1] = $args[_key];
|
|
1309
|
-
}
|
|
1310
|
-
|
|
1311
|
-
return $return(sendInvocationCall(invocationMapping[cmd], payload));
|
|
1312
|
-
|
|
1313
|
-
default:
|
|
1314
|
-
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];
|
|
1315
1381
|
}
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
}
|
|
1382
|
+
return sendInvocationCall(invocationMapping[cmd], payload);
|
|
1383
|
+
default:
|
|
1384
|
+
throw new Error('Command ' + cmd + ' not supported by driver');
|
|
1385
|
+
}
|
|
1320
1386
|
};
|
|
1387
|
+
|
|
1321
1388
|
/**
|
|
1322
1389
|
* Create a promise and send an invocation call to the frontend
|
|
1323
1390
|
*
|
|
@@ -1326,31 +1393,27 @@
|
|
|
1326
1393
|
*
|
|
1327
1394
|
* @return {Promise}
|
|
1328
1395
|
*/
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
var sendInvocationCall = function sendInvocationCall(process, args) {
|
|
1332
|
-
var promiseID = create();
|
|
1396
|
+
const sendInvocationCall = (process, args) => {
|
|
1397
|
+
const promiseID = create();
|
|
1333
1398
|
outMsgQueue.push([protocol.INVOCATION, promiseID, process, args]);
|
|
1334
1399
|
return get(promiseID);
|
|
1335
1400
|
};
|
|
1336
1401
|
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
Promise.race(realConnectionBucket).then(function (newConnector) {
|
|
1349
|
-
connector = newConnector;
|
|
1350
|
-
});
|
|
1351
|
-
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;
|
|
1352
1413
|
});
|
|
1414
|
+
return await Promise.race(fallbackConnectionBucket);
|
|
1353
1415
|
};
|
|
1416
|
+
|
|
1354
1417
|
/**
|
|
1355
1418
|
* Send a message to the App
|
|
1356
1419
|
*
|
|
@@ -1361,30 +1424,15 @@
|
|
|
1361
1424
|
* @param {any} payload that will be attached to the message
|
|
1362
1425
|
* @return {Promise<any>} result of the request
|
|
1363
1426
|
*/
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
return Promise.resolve(connector).then(function ($await_2) {
|
|
1375
|
-
try {
|
|
1376
|
-
sendFn = $await_2;
|
|
1377
|
-
|
|
1378
|
-
for (_len = $args.length, payload = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
1379
|
-
payload[_key - 1] = $args[_key];
|
|
1380
|
-
}
|
|
1381
|
-
|
|
1382
|
-
return $return(sendFn.apply(void 0, [msg].concat(payload)));
|
|
1383
|
-
} catch ($boundEx) {
|
|
1384
|
-
return $error($boundEx);
|
|
1385
|
-
}
|
|
1386
|
-
}, $error);
|
|
1387
|
-
});
|
|
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);
|
|
1388
1436
|
};
|
|
1389
1437
|
|
|
1390
1438
|
/**
|
|
@@ -1392,34 +1440,28 @@
|
|
|
1392
1440
|
*
|
|
1393
1441
|
* @return {Promise<string>}
|
|
1394
1442
|
*/
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
return new Promise(function ($return, $error) {
|
|
1398
|
-
return $return(sendMessage(commands.version));
|
|
1399
|
-
});
|
|
1443
|
+
const getVersion = async () => {
|
|
1444
|
+
return sendMessage(commands.version);
|
|
1400
1445
|
};
|
|
1446
|
+
|
|
1401
1447
|
/**
|
|
1402
1448
|
* Check if app is native.
|
|
1403
1449
|
*
|
|
1404
1450
|
* @return {Promise<boolean>}
|
|
1405
1451
|
*/
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
return new Promise(function ($return, $error) {
|
|
1409
|
-
return $return(sendMessage(commands.native));
|
|
1410
|
-
});
|
|
1452
|
+
const isNative = async () => {
|
|
1453
|
+
return sendMessage(commands.native);
|
|
1411
1454
|
};
|
|
1455
|
+
|
|
1412
1456
|
/**
|
|
1413
1457
|
* Check if app is mobile.
|
|
1414
1458
|
*
|
|
1415
1459
|
* @return {Promise<boolean>}
|
|
1416
1460
|
*/
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
return new Promise(function ($return, $error) {
|
|
1420
|
-
return $return(sendMessage(commands.mobile));
|
|
1421
|
-
});
|
|
1461
|
+
const isMobile = async () => {
|
|
1462
|
+
return sendMessage(commands.mobile);
|
|
1422
1463
|
};
|
|
1464
|
+
|
|
1423
1465
|
/**
|
|
1424
1466
|
* Open a link through the app.
|
|
1425
1467
|
*
|
|
@@ -1430,12 +1472,10 @@
|
|
|
1430
1472
|
*
|
|
1431
1473
|
* @return {Promise<any>}
|
|
1432
1474
|
*/
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
return new Promise(function ($return, $error) {
|
|
1436
|
-
return $return(sendMessage(commands.openLink, url));
|
|
1437
|
-
});
|
|
1475
|
+
const openLink$1 = async url => {
|
|
1476
|
+
return sendMessage(commands.openLink, url);
|
|
1438
1477
|
};
|
|
1478
|
+
|
|
1439
1479
|
/**
|
|
1440
1480
|
* Open a link explicitly in the external browser.
|
|
1441
1481
|
*
|
|
@@ -1443,14 +1483,12 @@
|
|
|
1443
1483
|
*
|
|
1444
1484
|
* @return {Promise<any>}
|
|
1445
1485
|
*/
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
return $return(sendMessage(commands.openLink, url, {
|
|
1450
|
-
inAppBrowser: false
|
|
1451
|
-
}));
|
|
1486
|
+
const openLinkExternal$1 = async url => {
|
|
1487
|
+
return sendMessage(commands.openLink, url, {
|
|
1488
|
+
inAppBrowser: false
|
|
1452
1489
|
});
|
|
1453
1490
|
};
|
|
1491
|
+
|
|
1454
1492
|
/**
|
|
1455
1493
|
* Open a link explicitly in the internal browser.
|
|
1456
1494
|
*
|
|
@@ -1458,14 +1496,12 @@
|
|
|
1458
1496
|
*
|
|
1459
1497
|
* @return {Promise<any>}
|
|
1460
1498
|
*/
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
return $return(sendMessage(commands.openLink, url, {
|
|
1465
|
-
inAppBrowser: true
|
|
1466
|
-
}));
|
|
1499
|
+
const openLinkInternal$1 = async url => {
|
|
1500
|
+
return sendMessage(commands.openLink, url, {
|
|
1501
|
+
inAppBrowser: true
|
|
1467
1502
|
});
|
|
1468
1503
|
};
|
|
1504
|
+
|
|
1469
1505
|
/**
|
|
1470
1506
|
* Open a native file upload dialog on device which do not support it by default.
|
|
1471
1507
|
*
|
|
@@ -1473,12 +1509,10 @@
|
|
|
1473
1509
|
*
|
|
1474
1510
|
* @return {Promise<any>}
|
|
1475
1511
|
*/
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
return new Promise(function ($return, $error) {
|
|
1479
|
-
return $return(sendMessage(commands.nativeUpload));
|
|
1480
|
-
});
|
|
1512
|
+
const openNativeFileDialog = async () => {
|
|
1513
|
+
return sendMessage(commands.nativeUpload);
|
|
1481
1514
|
};
|
|
1515
|
+
|
|
1482
1516
|
/**
|
|
1483
1517
|
* Open a share dialog on native devices
|
|
1484
1518
|
*
|
|
@@ -1494,51 +1528,37 @@
|
|
|
1494
1528
|
*
|
|
1495
1529
|
* @return {Promise<string>}
|
|
1496
1530
|
*/
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
return new Promise(function ($return, $error) {
|
|
1500
|
-
return $return(sendMessage(commands.nativeShare, content));
|
|
1501
|
-
});
|
|
1531
|
+
const openNativeShareDialog$1 = async content => {
|
|
1532
|
+
return sendMessage(commands.nativeShare, content);
|
|
1502
1533
|
};
|
|
1534
|
+
|
|
1503
1535
|
/**
|
|
1504
1536
|
* Get the content languages configured for the branch.
|
|
1505
1537
|
*
|
|
1506
1538
|
* @return {Promise<Object>}
|
|
1507
1539
|
*/
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
return new Promise(function ($return, $error) {
|
|
1511
|
-
return $return(sendMessage(commands.langInfos).then(function (res) {
|
|
1512
|
-
return res.branchLanguages;
|
|
1513
|
-
}));
|
|
1514
|
-
});
|
|
1540
|
+
const getBranchLanguages$1 = async () => {
|
|
1541
|
+
return sendMessage(commands.langInfos).then(res => res.branchLanguages);
|
|
1515
1542
|
};
|
|
1543
|
+
|
|
1516
1544
|
/**
|
|
1517
1545
|
* Get the default content language configured for the branch.
|
|
1518
1546
|
*
|
|
1519
1547
|
* @return {Promise<Object>}
|
|
1520
1548
|
*/
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
return new Promise(function ($return, $error) {
|
|
1524
|
-
return $return(sendMessage(commands.langInfos).then(function (res) {
|
|
1525
|
-
return res.branchDefaultLanguage;
|
|
1526
|
-
}));
|
|
1527
|
-
});
|
|
1549
|
+
const getBranchDefaultLanguage$1 = async () => {
|
|
1550
|
+
return sendMessage(commands.langInfos).then(res => res.branchDefaultLanguage);
|
|
1528
1551
|
};
|
|
1552
|
+
|
|
1529
1553
|
/**
|
|
1530
1554
|
* Get all content languages supported by the Staffbase app.
|
|
1531
1555
|
*
|
|
1532
1556
|
* @return {Promise<Object>}
|
|
1533
1557
|
*/
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
return new Promise(function ($return, $error) {
|
|
1537
|
-
return $return(sendMessage(commands.langInfos).then(function (res) {
|
|
1538
|
-
return res.contentLanguages;
|
|
1539
|
-
}));
|
|
1540
|
-
});
|
|
1558
|
+
const getContentLanguages$1 = async () => {
|
|
1559
|
+
return sendMessage(commands.langInfos).then(res => res.contentLanguages);
|
|
1541
1560
|
};
|
|
1561
|
+
|
|
1542
1562
|
/**
|
|
1543
1563
|
* Gets the chosen language from a given content object
|
|
1544
1564
|
*
|
|
@@ -1550,89 +1570,53 @@
|
|
|
1550
1570
|
*
|
|
1551
1571
|
* @return {Promise<string>}
|
|
1552
1572
|
*/
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
return new Promise(function ($return, $error) {
|
|
1556
|
-
return $return(sendMessage(commands.prefContentLang, content));
|
|
1557
|
-
});
|
|
1573
|
+
const getPreferredContentLocale$1 = async content => {
|
|
1574
|
+
return sendMessage(commands.prefContentLang, content);
|
|
1558
1575
|
};
|
|
1559
1576
|
|
|
1560
|
-
|
|
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) => {
|
|
1561
1585
|
// validate input and split into segments
|
|
1562
1586
|
const n1 = validateAndParse(v1);
|
|
1563
|
-
const n2 = validateAndParse(v2);
|
|
1564
|
-
|
|
1587
|
+
const n2 = validateAndParse(v2);
|
|
1588
|
+
// pop off the patch
|
|
1565
1589
|
const p1 = n1.pop();
|
|
1566
|
-
const p2 = n2.pop();
|
|
1567
|
-
|
|
1590
|
+
const p2 = n2.pop();
|
|
1591
|
+
// validate numbers
|
|
1568
1592
|
const r = compareSegments(n1, n2);
|
|
1569
|
-
if (r !== 0) return r;
|
|
1570
|
-
|
|
1593
|
+
if (r !== 0) return r;
|
|
1594
|
+
// validate pre-release
|
|
1571
1595
|
if (p1 && p2) {
|
|
1572
1596
|
return compareSegments(p1.split('.'), p2.split('.'));
|
|
1573
1597
|
} else if (p1 || p2) {
|
|
1574
1598
|
return p1 ? -1 : 1;
|
|
1575
1599
|
}
|
|
1576
|
-
|
|
1577
1600
|
return 0;
|
|
1578
|
-
}
|
|
1579
|
-
const validate = v => typeof v === 'string' && /^[v\d]/.test(v) && semver.test(v);
|
|
1580
|
-
const compare = (v1, v2, operator) => {
|
|
1581
|
-
// validate input operator
|
|
1582
|
-
assertValidOperator(operator); // since result of compareVersions can only be -1 or 0 or 1
|
|
1583
|
-
// a simple map can be used to replace switch
|
|
1584
|
-
|
|
1585
|
-
const res = compareVersions(v1, v2);
|
|
1586
|
-
return operatorResMap[operator].includes(res);
|
|
1587
1601
|
};
|
|
1588
|
-
const satisfies = (v, r) => {
|
|
1589
|
-
// if no range operator then "="
|
|
1590
|
-
const m = r.match(/^([<>=~^]+)/);
|
|
1591
|
-
const op = m ? m[1] : '='; // if gt/lt/eq then operator compare
|
|
1592
|
-
|
|
1593
|
-
if (op !== '^' && op !== '~') return compare(v, r, op); // else range of either "~" or "^" is assumed
|
|
1594
|
-
|
|
1595
|
-
const [v1, v2, v3] = validateAndParse(v);
|
|
1596
|
-
const [r1, r2, r3] = validateAndParse(r);
|
|
1597
|
-
if (compareStrings(v1, r1) !== 0) return false;
|
|
1598
|
-
|
|
1599
|
-
if (op === '^') {
|
|
1600
|
-
return compareSegments([v2, v3], [r2, r3]) >= 0;
|
|
1601
|
-
}
|
|
1602
|
-
|
|
1603
|
-
if (compareStrings(v2, r2) !== 0) return false;
|
|
1604
|
-
return compareStrings(v3, r3) >= 0;
|
|
1605
|
-
}; // export CJS style for parity
|
|
1606
|
-
|
|
1607
|
-
compareVersions.validate = validate;
|
|
1608
|
-
compareVersions.compare = compare;
|
|
1609
|
-
compareVersions.sastisfies = satisfies;
|
|
1610
1602
|
const semver = /^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i;
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
if (typeof v !== 'string') {
|
|
1603
|
+
const validateAndParse = version => {
|
|
1604
|
+
if (typeof version !== 'string') {
|
|
1614
1605
|
throw new TypeError('Invalid argument expected string');
|
|
1615
1606
|
}
|
|
1616
|
-
|
|
1617
|
-
const match = v.match(semver);
|
|
1618
|
-
|
|
1607
|
+
const match = version.match(semver);
|
|
1619
1608
|
if (!match) {
|
|
1620
|
-
throw new Error(`Invalid argument not valid semver ('${
|
|
1609
|
+
throw new Error(`Invalid argument not valid semver ('${version}' received)`);
|
|
1621
1610
|
}
|
|
1622
|
-
|
|
1623
1611
|
match.shift();
|
|
1624
1612
|
return match;
|
|
1625
1613
|
};
|
|
1626
|
-
|
|
1627
1614
|
const isWildcard = s => s === '*' || s === 'x' || s === 'X';
|
|
1628
|
-
|
|
1629
1615
|
const tryParse = v => {
|
|
1630
1616
|
const n = parseInt(v, 10);
|
|
1631
1617
|
return isNaN(n) ? v : n;
|
|
1632
1618
|
};
|
|
1633
|
-
|
|
1634
1619
|
const forceType = (a, b) => typeof a !== typeof b ? [String(a), String(b)] : [a, b];
|
|
1635
|
-
|
|
1636
1620
|
const compareStrings = (a, b) => {
|
|
1637
1621
|
if (isWildcard(a) || isWildcard(b)) return 0;
|
|
1638
1622
|
const [ap, bp] = forceType(tryParse(a), tryParse(b));
|
|
@@ -1640,152 +1624,97 @@
|
|
|
1640
1624
|
if (ap < bp) return -1;
|
|
1641
1625
|
return 0;
|
|
1642
1626
|
};
|
|
1643
|
-
|
|
1644
1627
|
const compareSegments = (a, b) => {
|
|
1645
1628
|
for (let i = 0; i < Math.max(a.length, b.length); i++) {
|
|
1646
|
-
const r = compareStrings(a[i] || 0, b[i] || 0);
|
|
1629
|
+
const r = compareStrings(a[i] || '0', b[i] || '0');
|
|
1647
1630
|
if (r !== 0) return r;
|
|
1648
1631
|
}
|
|
1649
|
-
|
|
1650
1632
|
return 0;
|
|
1651
1633
|
};
|
|
1652
1634
|
|
|
1653
|
-
|
|
1654
|
-
'>': [1],
|
|
1655
|
-
'>=': [0, 1],
|
|
1656
|
-
'=': [0],
|
|
1657
|
-
'<=': [-1, 0],
|
|
1658
|
-
'<': [-1]
|
|
1659
|
-
};
|
|
1660
|
-
const allowedOperators = Object.keys(operatorResMap);
|
|
1661
|
-
|
|
1662
|
-
const assertValidOperator = op => {
|
|
1663
|
-
if (typeof op !== 'string') {
|
|
1664
|
-
throw new TypeError(`Invalid operator type, expected string but got ${typeof op}`);
|
|
1665
|
-
}
|
|
1666
|
-
|
|
1667
|
-
if (allowedOperators.indexOf(op) === -1) {
|
|
1668
|
-
throw new Error(`Invalid operator, expected one of ${allowedOperators.join('|')}`);
|
|
1669
|
-
}
|
|
1670
|
-
};
|
|
1671
|
-
|
|
1635
|
+
/* eslint-disable no-unused-vars */
|
|
1672
1636
|
/**
|
|
1673
1637
|
* Check if device is using ios.
|
|
1674
1638
|
*
|
|
1675
1639
|
* @return {Promise<boolean>}
|
|
1676
1640
|
*/
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
return new Promise(function ($return, $error) {
|
|
1680
|
-
return $return(sendMessage(commands.ios));
|
|
1681
|
-
});
|
|
1641
|
+
const isIos = async () => {
|
|
1642
|
+
return sendMessage(commands.ios);
|
|
1682
1643
|
};
|
|
1644
|
+
|
|
1683
1645
|
/**
|
|
1684
1646
|
* Check if device is using android.
|
|
1685
1647
|
*
|
|
1686
1648
|
* @return {Promise<boolean>}
|
|
1687
1649
|
*/
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
return new Promise(function ($return, $error) {
|
|
1691
|
-
return $return(sendMessage(commands.android));
|
|
1692
|
-
});
|
|
1650
|
+
const isAndroid = async () => {
|
|
1651
|
+
return sendMessage(commands.android);
|
|
1693
1652
|
};
|
|
1653
|
+
|
|
1694
1654
|
/**
|
|
1695
1655
|
* Check if device is able to perform a download.
|
|
1696
1656
|
*
|
|
1697
1657
|
* @return {Promise<boolean>}
|
|
1698
1658
|
*/
|
|
1659
|
+
const canDownload = async () => {
|
|
1660
|
+
let [native, version, ios] = await Promise.all([isNative(), getVersion(), isIos()]);
|
|
1699
1661
|
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
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);
|
|
1703
1665
|
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
version = version.substring(0, dashIndex != -1 ? dashIndex : version.length); // mobile ios devices can not download with an app version less than 3.5
|
|
1709
|
-
// but apps below 3.5 don't have the platform information from the frontend available
|
|
1710
|
-
// so we disable download for all native ios devices under these conditions
|
|
1711
|
-
|
|
1712
|
-
return $return(!(compareVersions(version, '3.5') < 0 && native && ios));
|
|
1713
|
-
} catch ($boundEx) {
|
|
1714
|
-
return $error($boundEx);
|
|
1715
|
-
}
|
|
1716
|
-
}, $error);
|
|
1717
|
-
});
|
|
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);
|
|
1718
1670
|
};
|
|
1719
1671
|
|
|
1720
1672
|
/**
|
|
1721
1673
|
* Interface exports
|
|
1722
1674
|
*/
|
|
1675
|
+
|
|
1723
1676
|
/**
|
|
1724
1677
|
* Check if device is able to perform a download.
|
|
1725
1678
|
* @function
|
|
1726
1679
|
* @return {Promise<boolean>}
|
|
1727
1680
|
*/
|
|
1681
|
+
const deviceCanDownload = async () => canDownload();
|
|
1728
1682
|
|
|
1729
|
-
var deviceCanDownload = function deviceCanDownload() {
|
|
1730
|
-
return new Promise(function ($return, $error) {
|
|
1731
|
-
return $return(canDownload());
|
|
1732
|
-
});
|
|
1733
|
-
};
|
|
1734
1683
|
/**
|
|
1735
1684
|
* Check if device is using ios.
|
|
1736
1685
|
* @function
|
|
1737
1686
|
* @return {Promise<boolean>}
|
|
1738
1687
|
*/
|
|
1688
|
+
const isIosDevice = async () => isIos();
|
|
1739
1689
|
|
|
1740
|
-
var isIosDevice = function isIosDevice() {
|
|
1741
|
-
return new Promise(function ($return, $error) {
|
|
1742
|
-
return $return(isIos());
|
|
1743
|
-
});
|
|
1744
|
-
};
|
|
1745
1690
|
/**
|
|
1746
1691
|
* Check if device is using android.
|
|
1747
1692
|
* @function
|
|
1748
1693
|
* @return {Promise<boolean>}
|
|
1749
1694
|
*/
|
|
1695
|
+
const isAndroidDevice = async () => isAndroid();
|
|
1750
1696
|
|
|
1751
|
-
var isAndroidDevice = function isAndroidDevice() {
|
|
1752
|
-
return new Promise(function ($return, $error) {
|
|
1753
|
-
return $return(isAndroid());
|
|
1754
|
-
});
|
|
1755
|
-
};
|
|
1756
1697
|
/**
|
|
1757
1698
|
* Get the version of the Staffbase App.
|
|
1758
1699
|
* @function
|
|
1759
1700
|
* @return {Promise<string>}
|
|
1760
1701
|
*/
|
|
1702
|
+
const getAppVersion = async () => getVersion();
|
|
1761
1703
|
|
|
1762
|
-
var getAppVersion = function getAppVersion() {
|
|
1763
|
-
return new Promise(function ($return, $error) {
|
|
1764
|
-
return $return(getVersion());
|
|
1765
|
-
});
|
|
1766
|
-
};
|
|
1767
1704
|
/**
|
|
1768
1705
|
* Check if app is native.
|
|
1769
1706
|
* @function
|
|
1770
1707
|
* @return {Promise<boolean>}
|
|
1771
1708
|
*/
|
|
1709
|
+
const isNativeApp = async () => isNative();
|
|
1772
1710
|
|
|
1773
|
-
var isNativeApp = function isNativeApp() {
|
|
1774
|
-
return new Promise(function ($return, $error) {
|
|
1775
|
-
return $return(isNative());
|
|
1776
|
-
});
|
|
1777
|
-
};
|
|
1778
1711
|
/**
|
|
1779
1712
|
* Check if app is mobile.
|
|
1780
1713
|
* @function
|
|
1781
1714
|
* @return {Promise<boolean>}
|
|
1782
1715
|
*/
|
|
1716
|
+
const isMobileApp = async () => isMobile();
|
|
1783
1717
|
|
|
1784
|
-
var isMobileApp = function isMobileApp() {
|
|
1785
|
-
return new Promise(function ($return, $error) {
|
|
1786
|
-
return $return(isMobile());
|
|
1787
|
-
});
|
|
1788
|
-
};
|
|
1789
1718
|
/**
|
|
1790
1719
|
* Open a link through the app.
|
|
1791
1720
|
*
|
|
@@ -1796,12 +1725,8 @@
|
|
|
1796
1725
|
* @function
|
|
1797
1726
|
* @return {Promise<any>}
|
|
1798
1727
|
*/
|
|
1728
|
+
const openLink = async url => openLink$1(url);
|
|
1799
1729
|
|
|
1800
|
-
var openLink = function openLink(url) {
|
|
1801
|
-
return new Promise(function ($return, $error) {
|
|
1802
|
-
return $return(openLink$1(url));
|
|
1803
|
-
});
|
|
1804
|
-
};
|
|
1805
1730
|
/**
|
|
1806
1731
|
* Open a link explicitly in the external browser.
|
|
1807
1732
|
*
|
|
@@ -1809,12 +1734,8 @@
|
|
|
1809
1734
|
* @function
|
|
1810
1735
|
* @return {Promise<any>}
|
|
1811
1736
|
*/
|
|
1737
|
+
const openLinkExternal = async url => openLinkExternal$1(url);
|
|
1812
1738
|
|
|
1813
|
-
var openLinkExternal = function openLinkExternal(url) {
|
|
1814
|
-
return new Promise(function ($return, $error) {
|
|
1815
|
-
return $return(openLinkExternal$1(url));
|
|
1816
|
-
});
|
|
1817
|
-
};
|
|
1818
1739
|
/**
|
|
1819
1740
|
* Open a link explicitly in the internal browser.
|
|
1820
1741
|
*
|
|
@@ -1822,45 +1743,29 @@
|
|
|
1822
1743
|
* @function
|
|
1823
1744
|
* @return {Promise<any>}
|
|
1824
1745
|
*/
|
|
1746
|
+
const openLinkInternal = async url => openLinkInternal$1(url);
|
|
1825
1747
|
|
|
1826
|
-
var openLinkInternal = function openLinkInternal(url) {
|
|
1827
|
-
return new Promise(function ($return, $error) {
|
|
1828
|
-
return $return(openLinkInternal$1(url));
|
|
1829
|
-
});
|
|
1830
|
-
};
|
|
1831
1748
|
/**
|
|
1832
1749
|
* Get all enabled content languages configured in the app.
|
|
1833
1750
|
* @function
|
|
1834
1751
|
* @return {Promise<any>}
|
|
1835
1752
|
*/
|
|
1753
|
+
const getBranchLanguages = async () => getBranchLanguages$1();
|
|
1836
1754
|
|
|
1837
|
-
var getBranchLanguages = function getBranchLanguages() {
|
|
1838
|
-
return new Promise(function ($return, $error) {
|
|
1839
|
-
return $return(getBranchLanguages$1());
|
|
1840
|
-
});
|
|
1841
|
-
};
|
|
1842
1755
|
/**
|
|
1843
1756
|
* Get the default content language configured in the app.
|
|
1844
1757
|
* @function
|
|
1845
1758
|
* @return {Promise<any>}
|
|
1846
1759
|
*/
|
|
1760
|
+
const getBranchDefaultLanguage = async () => getBranchDefaultLanguage$1();
|
|
1847
1761
|
|
|
1848
|
-
var getBranchDefaultLanguage = function getBranchDefaultLanguage() {
|
|
1849
|
-
return new Promise(function ($return, $error) {
|
|
1850
|
-
return $return(getBranchDefaultLanguage$1());
|
|
1851
|
-
});
|
|
1852
|
-
};
|
|
1853
1762
|
/**
|
|
1854
1763
|
* Get all content languages supported by the app.
|
|
1855
1764
|
* @function
|
|
1856
1765
|
* @return {Promise<any>}
|
|
1857
1766
|
*/
|
|
1767
|
+
const getContentLanguages = async () => getContentLanguages$1();
|
|
1858
1768
|
|
|
1859
|
-
var getContentLanguages = function getContentLanguages() {
|
|
1860
|
-
return new Promise(function ($return, $error) {
|
|
1861
|
-
return $return(getContentLanguages$1());
|
|
1862
|
-
});
|
|
1863
|
-
};
|
|
1864
1769
|
/**
|
|
1865
1770
|
* Gets the chosen language from a given content object
|
|
1866
1771
|
*
|
|
@@ -1872,12 +1777,8 @@
|
|
|
1872
1777
|
* @function
|
|
1873
1778
|
* @return {Promise<string>}
|
|
1874
1779
|
*/
|
|
1780
|
+
const getPreferredContentLocale = async content => getPreferredContentLocale$1(content);
|
|
1875
1781
|
|
|
1876
|
-
var getPreferredContentLocale = function getPreferredContentLocale(content) {
|
|
1877
|
-
return new Promise(function ($return, $error) {
|
|
1878
|
-
return $return(getPreferredContentLocale$1(content));
|
|
1879
|
-
});
|
|
1880
|
-
};
|
|
1881
1782
|
/**
|
|
1882
1783
|
* Open a share dialog on native devices
|
|
1883
1784
|
*
|
|
@@ -1893,13 +1794,8 @@
|
|
|
1893
1794
|
*
|
|
1894
1795
|
* @return {Promise<string>}
|
|
1895
1796
|
*/
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
return new Promise(function ($return, $error) {
|
|
1899
|
-
return $return(openNativeShareDialog$1(content));
|
|
1900
|
-
});
|
|
1901
|
-
};
|
|
1902
|
-
/* experimental */
|
|
1797
|
+
const openNativeShareDialog = async content => openNativeShareDialog$1(content);
|
|
1798
|
+
/* experimental */
|
|
1903
1799
|
|
|
1904
1800
|
exports.deviceCanDownload = deviceCanDownload;
|
|
1905
1801
|
exports.getAppVersion = getAppVersion;
|
|
@@ -1917,7 +1813,5 @@
|
|
|
1917
1813
|
exports.openNativeFileDialog = openNativeFileDialog;
|
|
1918
1814
|
exports.openNativeShareDialog = openNativeShareDialog;
|
|
1919
1815
|
|
|
1920
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1921
|
-
|
|
1922
1816
|
}));
|
|
1923
1817
|
//# sourceMappingURL=plugins-client-sdk.umd.js.map
|