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