@staffbase/plugins-client-sdk 1.1.1 → 1.2.2

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.
@@ -1,780 +1,313 @@
1
+ /**
2
+ * Bundle of @staffbase/plugins-client-sdk
3
+ * @file Staffbase plugins client SDK for JavaScript
4
+ * @see https://github.com/Staffbase/plugins-client-sdk#readme
5
+ * @version 1.2.1
6
+ *
7
+ * @author Stefan Staude <stefan.staude@staffbase.com>
8
+ * @author Daniel Große <daniel.grosse@staffbase.com>
9
+ *
10
+ * @copyright 2022
11
+ * @license Apache-2.0
12
+ */
13
+
1
14
  (function (global, factory) {
2
15
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
16
  typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (global = global || self, factory(global['plugins-client-sdk'] = {}));
5
- }(this, function (exports) { 'use strict';
17
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["plugins-client-sdk"] = {}));
18
+ })(this, (function (exports) { 'use strict';
6
19
 
7
20
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
8
21
 
9
- function createCommonjsModule(fn, module) {
10
- return module = { exports: {} }, fn(module, module.exports), module.exports;
11
- }
12
-
13
- var runtime_1 = createCommonjsModule(function (module) {
14
- /**
15
- * Copyright (c) 2014-present, Facebook, Inc.
16
- *
17
- * This source code is licensed under the MIT license found in the
18
- * LICENSE file in the root directory of this source tree.
19
- */
20
-
21
- var runtime = (function (exports) {
22
-
23
- var Op = Object.prototype;
24
- var hasOwn = Op.hasOwnProperty;
25
- var undefined$1; // More compressible than void 0.
26
- var $Symbol = typeof Symbol === "function" ? Symbol : {};
27
- var iteratorSymbol = $Symbol.iterator || "@@iterator";
28
- var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
29
- var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
22
+ var loglevel = {exports: {}};
30
23
 
31
- function wrap(innerFn, outerFn, self, tryLocsList) {
32
- // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
33
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
34
- var generator = Object.create(protoGenerator.prototype);
35
- var context = new Context(tryLocsList || []);
24
+ /*
25
+ * loglevel - https://github.com/pimterry/loglevel
26
+ *
27
+ * Copyright (c) 2013 Tim Perry
28
+ * Licensed under the MIT license.
29
+ */
36
30
 
37
- // The ._invoke method unifies the implementations of the .next,
38
- // .throw, and .return methods.
39
- generator._invoke = makeInvokeMethod(innerFn, self, context);
31
+ (function (module) {
32
+ (function (root, definition) {
40
33
 
41
- return generator;
42
- }
43
- exports.wrap = wrap;
44
-
45
- // Try/catch helper to minimize deoptimizations. Returns a completion
46
- // record like context.tryEntries[i].completion. This interface could
47
- // have been (and was previously) designed to take a closure to be
48
- // invoked without arguments, but in all the cases we care about we
49
- // already have an existing method we want to call, so there's no need
50
- // to create a new function object. We can even get away with assuming
51
- // the method takes exactly one argument, since that happens to be true
52
- // in every case, so we don't have to touch the arguments object. The
53
- // only additional allocation required is the completion record, which
54
- // has a stable shape and so hopefully should be cheap to allocate.
55
- function tryCatch(fn, obj, arg) {
56
- try {
57
- return { type: "normal", arg: fn.call(obj, arg) };
58
- } catch (err) {
59
- return { type: "throw", arg: err };
34
+ if (module.exports) {
35
+ module.exports = definition();
36
+ } else {
37
+ root.log = definition();
60
38
  }
61
- }
62
-
63
- var GenStateSuspendedStart = "suspendedStart";
64
- var GenStateSuspendedYield = "suspendedYield";
65
- var GenStateExecuting = "executing";
66
- var GenStateCompleted = "completed";
67
-
68
- // Returning this object from the innerFn has the same effect as
69
- // breaking out of the dispatch switch statement.
70
- var ContinueSentinel = {};
71
-
72
- // Dummy constructor functions that we use as the .constructor and
73
- // .constructor.prototype properties for functions that return Generator
74
- // objects. For full spec compliance, you may wish to configure your
75
- // minifier not to mangle the names of these two functions.
76
- function Generator() {}
77
- function GeneratorFunction() {}
78
- function GeneratorFunctionPrototype() {}
79
-
80
- // This is a polyfill for %IteratorPrototype% for environments that
81
- // don't natively support it.
82
- var IteratorPrototype = {};
83
- IteratorPrototype[iteratorSymbol] = function () {
84
- return this;
85
- };
86
-
87
- var getProto = Object.getPrototypeOf;
88
- var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
89
- if (NativeIteratorPrototype &&
90
- NativeIteratorPrototype !== Op &&
91
- hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
92
- // This environment has a native %IteratorPrototype%; use it instead
93
- // of the polyfill.
94
- IteratorPrototype = NativeIteratorPrototype;
95
- }
39
+ })(commonjsGlobal, function () {
96
40
 
97
- var Gp = GeneratorFunctionPrototype.prototype =
98
- Generator.prototype = Object.create(IteratorPrototype);
99
- GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
100
- GeneratorFunctionPrototype.constructor = GeneratorFunction;
101
- GeneratorFunctionPrototype[toStringTagSymbol] =
102
- GeneratorFunction.displayName = "GeneratorFunction";
103
-
104
- // Helper for defining the .next, .throw, and .return methods of the
105
- // Iterator interface in terms of a single ._invoke method.
106
- function defineIteratorMethods(prototype) {
107
- ["next", "throw", "return"].forEach(function(method) {
108
- prototype[method] = function(arg) {
109
- return this._invoke(method, arg);
110
- };
111
- });
112
- }
113
-
114
- exports.isGeneratorFunction = function(genFun) {
115
- var ctor = typeof genFun === "function" && genFun.constructor;
116
- return ctor
117
- ? ctor === GeneratorFunction ||
118
- // For the native GeneratorFunction constructor, the best we can
119
- // do is to check its .name property.
120
- (ctor.displayName || ctor.name) === "GeneratorFunction"
121
- : false;
122
- };
41
+ var noop = function () {};
123
42
 
124
- exports.mark = function(genFun) {
125
- if (Object.setPrototypeOf) {
126
- Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
127
- } else {
128
- genFun.__proto__ = GeneratorFunctionPrototype;
129
- if (!(toStringTagSymbol in genFun)) {
130
- genFun[toStringTagSymbol] = "GeneratorFunction";
131
- }
132
- }
133
- genFun.prototype = Object.create(Gp);
134
- return genFun;
135
- };
43
+ var undefinedType = "undefined";
44
+ var isIE = typeof window !== undefinedType && typeof window.navigator !== undefinedType && /Trident\/|MSIE /.test(window.navigator.userAgent);
45
+ var logMethods = ["trace", "debug", "info", "warn", "error"]; // Cross-browser bind equivalent that works at least back to IE6
136
46
 
137
- // Within the body of any async function, `await x` is transformed to
138
- // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
139
- // `hasOwn.call(value, "__await")` to determine if the yielded value is
140
- // meant to be awaited.
141
- exports.awrap = function(arg) {
142
- return { __await: arg };
143
- };
47
+ function bindMethod(obj, methodName) {
48
+ var method = obj[methodName];
144
49
 
145
- function AsyncIterator(generator) {
146
- function invoke(method, arg, resolve, reject) {
147
- var record = tryCatch(generator[method], generator, arg);
148
- if (record.type === "throw") {
149
- reject(record.arg);
50
+ if (typeof method.bind === 'function') {
51
+ return method.bind(obj);
150
52
  } else {
151
- var result = record.arg;
152
- var value = result.value;
153
- if (value &&
154
- typeof value === "object" &&
155
- hasOwn.call(value, "__await")) {
156
- return Promise.resolve(value.__await).then(function(value) {
157
- invoke("next", value, resolve, reject);
158
- }, function(err) {
159
- invoke("throw", err, resolve, reject);
160
- });
53
+ try {
54
+ return Function.prototype.bind.call(method, obj);
55
+ } catch (e) {
56
+ // Missing bind shim or IE8 + Modernizr, fallback to wrapping
57
+ return function () {
58
+ return Function.prototype.apply.apply(method, [obj, arguments]);
59
+ };
161
60
  }
162
-
163
- return Promise.resolve(value).then(function(unwrapped) {
164
- // When a yielded Promise is resolved, its final value becomes
165
- // the .value of the Promise<{value,done}> result for the
166
- // current iteration.
167
- result.value = unwrapped;
168
- resolve(result);
169
- }, function(error) {
170
- // If a rejected Promise was yielded, throw the rejection back
171
- // into the async generator function so it can be handled there.
172
- return invoke("throw", error, resolve, reject);
173
- });
174
61
  }
175
- }
62
+ } // Trace() doesn't print the message in IE, so for that case we need to wrap it
176
63
 
177
- var previousPromise;
178
64
 
179
- function enqueue(method, arg) {
180
- function callInvokeWithMethodAndArg() {
181
- return new Promise(function(resolve, reject) {
182
- invoke(method, arg, resolve, reject);
183
- });
65
+ function traceForIE() {
66
+ if (console.log) {
67
+ if (console.log.apply) {
68
+ console.log.apply(console, arguments);
69
+ } else {
70
+ // In old IE, native console methods themselves don't have apply().
71
+ Function.prototype.apply.apply(console.log, [console, arguments]);
72
+ }
184
73
  }
185
74
 
186
- return previousPromise =
187
- // If enqueue has been called before, then we want to wait until
188
- // all previous Promises have been resolved before calling invoke,
189
- // so that results are always delivered in the correct order. If
190
- // enqueue has not been called before, then it is important to
191
- // call invoke immediately, without waiting on a callback to fire,
192
- // so that the async generator function has the opportunity to do
193
- // any necessary setup in a predictable way. This predictability
194
- // is why the Promise constructor synchronously invokes its
195
- // executor callback, and why async functions synchronously
196
- // execute code before the first await. Since we implement simple
197
- // async functions in terms of async generators, it is especially
198
- // important to get this right, even though it requires care.
199
- previousPromise ? previousPromise.then(
200
- callInvokeWithMethodAndArg,
201
- // Avoid propagating failures to Promises returned by later
202
- // invocations of the iterator.
203
- callInvokeWithMethodAndArg
204
- ) : callInvokeWithMethodAndArg();
205
- }
206
-
207
- // Define the unified helper method that is used to implement .next,
208
- // .throw, and .return (see defineIteratorMethods).
209
- this._invoke = enqueue;
210
- }
211
-
212
- defineIteratorMethods(AsyncIterator.prototype);
213
- AsyncIterator.prototype[asyncIteratorSymbol] = function () {
214
- return this;
215
- };
216
- exports.AsyncIterator = AsyncIterator;
217
-
218
- // Note that simple async functions are implemented on top of
219
- // AsyncIterator objects; they just return a Promise for the value of
220
- // the final result produced by the iterator.
221
- exports.async = function(innerFn, outerFn, self, tryLocsList) {
222
- var iter = new AsyncIterator(
223
- wrap(innerFn, outerFn, self, tryLocsList)
224
- );
225
-
226
- return exports.isGeneratorFunction(outerFn)
227
- ? iter // If outerFn is a generator, return the full iterator.
228
- : iter.next().then(function(result) {
229
- return result.done ? result.value : iter.next();
230
- });
231
- };
75
+ if (console.trace) console.trace();
76
+ } // Build the best logging method possible for this env
77
+ // Wherever possible we want to bind, not wrap, to preserve stack traces
232
78
 
233
- function makeInvokeMethod(innerFn, self, context) {
234
- var state = GenStateSuspendedStart;
235
79
 
236
- return function invoke(method, arg) {
237
- if (state === GenStateExecuting) {
238
- throw new Error("Generator is already running");
80
+ function realMethod(methodName) {
81
+ if (methodName === 'debug') {
82
+ methodName = 'log';
239
83
  }
240
84
 
241
- if (state === GenStateCompleted) {
242
- if (method === "throw") {
243
- throw arg;
244
- }
245
-
246
- // Be forgiving, per 25.3.3.3.3 of the spec:
247
- // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
248
- return doneResult();
85
+ if (typeof console === undefinedType) {
86
+ return false; // No method possible, for now - fixed later by enableLoggingWhenConsoleArrives
87
+ } else if (methodName === 'trace' && isIE) {
88
+ return traceForIE;
89
+ } else if (console[methodName] !== undefined) {
90
+ return bindMethod(console, methodName);
91
+ } else if (console.log !== undefined) {
92
+ return bindMethod(console, 'log');
93
+ } else {
94
+ return noop;
249
95
  }
96
+ } // These private functions always need `this` to be set properly
250
97
 
251
- context.method = method;
252
- context.arg = arg;
253
-
254
- while (true) {
255
- var delegate = context.delegate;
256
- if (delegate) {
257
- var delegateResult = maybeInvokeDelegate(delegate, context);
258
- if (delegateResult) {
259
- if (delegateResult === ContinueSentinel) continue;
260
- return delegateResult;
261
- }
262
- }
263
-
264
- if (context.method === "next") {
265
- // Setting context._sent for legacy support of Babel's
266
- // function.sent implementation.
267
- context.sent = context._sent = context.arg;
268
-
269
- } else if (context.method === "throw") {
270
- if (state === GenStateSuspendedStart) {
271
- state = GenStateCompleted;
272
- throw context.arg;
273
- }
274
-
275
- context.dispatchException(context.arg);
276
-
277
- } else if (context.method === "return") {
278
- context.abrupt("return", context.arg);
279
- }
280
-
281
- state = GenStateExecuting;
282
98
 
283
- var record = tryCatch(innerFn, self, context);
284
- if (record.type === "normal") {
285
- // If an exception is thrown from innerFn, we leave state ===
286
- // GenStateExecuting and loop back for another invocation.
287
- state = context.done
288
- ? GenStateCompleted
289
- : GenStateSuspendedYield;
99
+ function replaceLoggingMethods(level, loggerName) {
100
+ /*jshint validthis:true */
101
+ for (var i = 0; i < logMethods.length; i++) {
102
+ var methodName = logMethods[i];
103
+ this[methodName] = i < level ? noop : this.methodFactory(methodName, level, loggerName);
104
+ } // Define log.log as an alias for log.debug
290
105
 
291
- if (record.arg === ContinueSentinel) {
292
- continue;
293
- }
294
106
 
295
- return {
296
- value: record.arg,
297
- done: context.done
298
- };
107
+ this.log = this.debug;
108
+ } // In old IE versions, the console isn't present until you first open it.
109
+ // We build realMethod() replacements here that regenerate logging methods
299
110
 
300
- } else if (record.type === "throw") {
301
- state = GenStateCompleted;
302
- // Dispatch the exception by looping back around to the
303
- // context.dispatchException(context.arg) call above.
304
- context.method = "throw";
305
- context.arg = record.arg;
306
- }
307
- }
308
- };
309
- }
310
111
 
311
- // Call delegate.iterator[context.method](context.arg) and handle the
312
- // result, either by returning a { value, done } result from the
313
- // delegate iterator, or by modifying context.method and context.arg,
314
- // setting context.delegate to null, and returning the ContinueSentinel.
315
- function maybeInvokeDelegate(delegate, context) {
316
- var method = delegate.iterator[context.method];
317
- if (method === undefined$1) {
318
- // A .throw or .return when the delegate iterator has no .throw
319
- // method always terminates the yield* loop.
320
- context.delegate = null;
321
-
322
- if (context.method === "throw") {
323
- // Note: ["return"] must be used for ES3 parsing compatibility.
324
- if (delegate.iterator["return"]) {
325
- // If the delegate iterator has a return method, give it a
326
- // chance to clean up.
327
- context.method = "return";
328
- context.arg = undefined$1;
329
- maybeInvokeDelegate(delegate, context);
330
-
331
- if (context.method === "throw") {
332
- // If maybeInvokeDelegate(context) changed context.method from
333
- // "return" to "throw", let that override the TypeError below.
334
- return ContinueSentinel;
335
- }
112
+ function enableLoggingWhenConsoleArrives(methodName, level, loggerName) {
113
+ return function () {
114
+ if (typeof console !== undefinedType) {
115
+ replaceLoggingMethods.call(this, level, loggerName);
116
+ this[methodName].apply(this, arguments);
336
117
  }
118
+ };
119
+ } // By default, we use closely bound real methods wherever possible, and
120
+ // otherwise we wait for a console to appear, and then try again.
337
121
 
338
- context.method = "throw";
339
- context.arg = new TypeError(
340
- "The iterator does not provide a 'throw' method");
341
- }
342
-
343
- return ContinueSentinel;
344
- }
345
-
346
- var record = tryCatch(method, delegate.iterator, context.arg);
347
122
 
348
- if (record.type === "throw") {
349
- context.method = "throw";
350
- context.arg = record.arg;
351
- context.delegate = null;
352
- return ContinueSentinel;
123
+ function defaultMethodFactory(methodName, level, loggerName) {
124
+ /*jshint validthis:true */
125
+ return realMethod(methodName) || enableLoggingWhenConsoleArrives.apply(this, arguments);
353
126
  }
354
127
 
355
- var info = record.arg;
356
-
357
- if (! info) {
358
- context.method = "throw";
359
- context.arg = new TypeError("iterator result is not an object");
360
- context.delegate = null;
361
- return ContinueSentinel;
362
- }
128
+ function Logger(name, defaultLevel, factory) {
129
+ var self = this;
130
+ var currentLevel;
131
+ defaultLevel = defaultLevel == null ? "WARN" : defaultLevel;
132
+ var storageKey = "loglevel";
363
133
 
364
- if (info.done) {
365
- // Assign the result of the finished delegate to the temporary
366
- // variable specified by delegate.resultName (see delegateYield).
367
- context[delegate.resultName] = info.value;
368
-
369
- // Resume execution at the desired location (see delegateYield).
370
- context.next = delegate.nextLoc;
371
-
372
- // If context.method was "throw" but the delegate handled the
373
- // exception, let the outer generator proceed normally. If
374
- // context.method was "next", forget context.arg since it has been
375
- // "consumed" by the delegate iterator. If context.method was
376
- // "return", allow the original .return call to continue in the
377
- // outer generator.
378
- if (context.method !== "return") {
379
- context.method = "next";
380
- context.arg = undefined$1;
134
+ if (typeof name === "string") {
135
+ storageKey += ":" + name;
136
+ } else if (typeof name === "symbol") {
137
+ storageKey = undefined;
381
138
  }
382
139
 
383
- } else {
384
- // Re-yield the result returned by the delegate method.
385
- return info;
386
- }
387
-
388
- // The delegate iterator is finished, so forget it and continue with
389
- // the outer generator.
390
- context.delegate = null;
391
- return ContinueSentinel;
392
- }
393
-
394
- // Define Generator.prototype.{next,throw,return} in terms of the
395
- // unified ._invoke helper method.
396
- defineIteratorMethods(Gp);
140
+ function persistLevelIfPossible(levelNum) {
141
+ var levelName = (logMethods[levelNum] || 'silent').toUpperCase();
142
+ if (typeof window === undefinedType || !storageKey) return; // Use localStorage if available
397
143
 
398
- Gp[toStringTagSymbol] = "Generator";
144
+ try {
145
+ window.localStorage[storageKey] = levelName;
146
+ return;
147
+ } catch (ignore) {} // Use session cookie as fallback
399
148
 
400
- // A Generator should always return itself as the iterator object when the
401
- // @@iterator function is called on it. Some browsers' implementations of the
402
- // iterator prototype chain incorrectly implement this, causing the Generator
403
- // object to not be returned from this call. This ensures that doesn't happen.
404
- // See https://github.com/facebook/regenerator/issues/274 for more details.
405
- Gp[iteratorSymbol] = function() {
406
- return this;
407
- };
408
149
 
409
- Gp.toString = function() {
410
- return "[object Generator]";
411
- };
150
+ try {
151
+ window.document.cookie = encodeURIComponent(storageKey) + "=" + levelName + ";";
152
+ } catch (ignore) {}
153
+ }
412
154
 
413
- function pushTryEntry(locs) {
414
- var entry = { tryLoc: locs[0] };
155
+ function getPersistedLevel() {
156
+ var storedLevel;
157
+ if (typeof window === undefinedType || !storageKey) return;
415
158
 
416
- if (1 in locs) {
417
- entry.catchLoc = locs[1];
418
- }
159
+ try {
160
+ storedLevel = window.localStorage[storageKey];
161
+ } catch (ignore) {} // Fallback to cookies if local storage gives us nothing
419
162
 
420
- if (2 in locs) {
421
- entry.finallyLoc = locs[2];
422
- entry.afterLoc = locs[3];
423
- }
424
163
 
425
- this.tryEntries.push(entry);
426
- }
164
+ if (typeof storedLevel === undefinedType) {
165
+ try {
166
+ var cookie = window.document.cookie;
167
+ var location = cookie.indexOf(encodeURIComponent(storageKey) + "=");
427
168
 
428
- function resetTryEntry(entry) {
429
- var record = entry.completion || {};
430
- record.type = "normal";
431
- delete record.arg;
432
- entry.completion = record;
433
- }
169
+ if (location !== -1) {
170
+ storedLevel = /^([^;]+)/.exec(cookie.slice(location))[1];
171
+ }
172
+ } catch (ignore) {}
173
+ } // If the stored level is not valid, treat it as if nothing was stored.
434
174
 
435
- function Context(tryLocsList) {
436
- // The root entry object (effectively a try statement without a catch
437
- // or a finally block) gives us a place to store values thrown from
438
- // locations where there is no enclosing try statement.
439
- this.tryEntries = [{ tryLoc: "root" }];
440
- tryLocsList.forEach(pushTryEntry, this);
441
- this.reset(true);
442
- }
443
175
 
444
- exports.keys = function(object) {
445
- var keys = [];
446
- for (var key in object) {
447
- keys.push(key);
448
- }
449
- keys.reverse();
450
-
451
- // Rather than returning an object with a next method, we keep
452
- // things simple and return the next function itself.
453
- return function next() {
454
- while (keys.length) {
455
- var key = keys.pop();
456
- if (key in object) {
457
- next.value = key;
458
- next.done = false;
459
- return next;
176
+ if (self.levels[storedLevel] === undefined) {
177
+ storedLevel = undefined;
460
178
  }
461
- }
462
-
463
- // To avoid creating an additional object, we just hang the .value
464
- // and .done properties off the next function object itself. This
465
- // also ensures that the minifier will not anonymize the function.
466
- next.done = true;
467
- return next;
468
- };
469
- };
470
-
471
- function values(iterable) {
472
- if (iterable) {
473
- var iteratorMethod = iterable[iteratorSymbol];
474
- if (iteratorMethod) {
475
- return iteratorMethod.call(iterable);
476
- }
477
179
 
478
- if (typeof iterable.next === "function") {
479
- return iterable;
180
+ return storedLevel;
480
181
  }
481
182
 
482
- if (!isNaN(iterable.length)) {
483
- var i = -1, next = function next() {
484
- while (++i < iterable.length) {
485
- if (hasOwn.call(iterable, i)) {
486
- next.value = iterable[i];
487
- next.done = false;
488
- return next;
489
- }
490
- }
183
+ function clearPersistedLevel() {
184
+ if (typeof window === undefinedType || !storageKey) return; // Use localStorage if available
491
185
 
492
- next.value = undefined$1;
493
- next.done = true;
186
+ try {
187
+ window.localStorage.removeItem(storageKey);
188
+ return;
189
+ } catch (ignore) {} // Use session cookie as fallback
494
190
 
495
- return next;
496
- };
497
191
 
498
- return next.next = next;
192
+ try {
193
+ window.document.cookie = encodeURIComponent(storageKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
194
+ } catch (ignore) {}
499
195
  }
500
- }
501
-
502
- // Return an iterator with no values.
503
- return { next: doneResult };
504
- }
505
- exports.values = values;
196
+ /*
197
+ *
198
+ * Public logger API - see https://github.com/pimterry/loglevel for details
199
+ *
200
+ */
201
+
202
+
203
+ self.name = name;
204
+ self.levels = {
205
+ "TRACE": 0,
206
+ "DEBUG": 1,
207
+ "INFO": 2,
208
+ "WARN": 3,
209
+ "ERROR": 4,
210
+ "SILENT": 5
211
+ };
212
+ self.methodFactory = factory || defaultMethodFactory;
506
213
 
507
- function doneResult() {
508
- return { value: undefined$1, done: true };
509
- }
214
+ self.getLevel = function () {
215
+ return currentLevel;
216
+ };
510
217
 
511
- Context.prototype = {
512
- constructor: Context,
513
-
514
- reset: function(skipTempReset) {
515
- this.prev = 0;
516
- this.next = 0;
517
- // Resetting context._sent for legacy support of Babel's
518
- // function.sent implementation.
519
- this.sent = this._sent = undefined$1;
520
- this.done = false;
521
- this.delegate = null;
522
-
523
- this.method = "next";
524
- this.arg = undefined$1;
525
-
526
- this.tryEntries.forEach(resetTryEntry);
527
-
528
- if (!skipTempReset) {
529
- for (var name in this) {
530
- // Not sure about the optimal order of these conditions:
531
- if (name.charAt(0) === "t" &&
532
- hasOwn.call(this, name) &&
533
- !isNaN(+name.slice(1))) {
534
- this[name] = undefined$1;
535
- }
218
+ self.setLevel = function (level, persist) {
219
+ if (typeof level === "string" && self.levels[level.toUpperCase()] !== undefined) {
220
+ level = self.levels[level.toUpperCase()];
536
221
  }
537
- }
538
- },
539
222
 
540
- stop: function() {
541
- this.done = true;
542
-
543
- var rootEntry = this.tryEntries[0];
544
- var rootRecord = rootEntry.completion;
545
- if (rootRecord.type === "throw") {
546
- throw rootRecord.arg;
547
- }
223
+ if (typeof level === "number" && level >= 0 && level <= self.levels.SILENT) {
224
+ currentLevel = level;
548
225
 
549
- return this.rval;
550
- },
226
+ if (persist !== false) {
227
+ // defaults to true
228
+ persistLevelIfPossible(level);
229
+ }
551
230
 
552
- dispatchException: function(exception) {
553
- if (this.done) {
554
- throw exception;
555
- }
231
+ replaceLoggingMethods.call(self, level, name);
556
232
 
557
- var context = this;
558
- function handle(loc, caught) {
559
- record.type = "throw";
560
- record.arg = exception;
561
- context.next = loc;
562
-
563
- if (caught) {
564
- // If the dispatched exception was caught by a catch block,
565
- // then let that catch block handle the exception normally.
566
- context.method = "next";
567
- context.arg = undefined$1;
233
+ if (typeof console === undefinedType && level < self.levels.SILENT) {
234
+ return "No console available for logging";
235
+ }
236
+ } else {
237
+ throw "log.setLevel() called with invalid level: " + level;
568
238
  }
239
+ };
569
240
 
570
- return !! caught;
571
- }
572
-
573
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
574
- var entry = this.tryEntries[i];
575
- var record = entry.completion;
241
+ self.setDefaultLevel = function (level) {
242
+ defaultLevel = level;
576
243
 
577
- if (entry.tryLoc === "root") {
578
- // Exception thrown outside of any try block that could handle
579
- // it, so set the completion value of the entire function to
580
- // throw the exception.
581
- return handle("end");
244
+ if (!getPersistedLevel()) {
245
+ self.setLevel(level, false);
582
246
  }
247
+ };
583
248
 
584
- if (entry.tryLoc <= this.prev) {
585
- var hasCatch = hasOwn.call(entry, "catchLoc");
586
- var hasFinally = hasOwn.call(entry, "finallyLoc");
587
-
588
- if (hasCatch && hasFinally) {
589
- if (this.prev < entry.catchLoc) {
590
- return handle(entry.catchLoc, true);
591
- } else if (this.prev < entry.finallyLoc) {
592
- return handle(entry.finallyLoc);
593
- }
594
-
595
- } else if (hasCatch) {
596
- if (this.prev < entry.catchLoc) {
597
- return handle(entry.catchLoc, true);
598
- }
599
-
600
- } else if (hasFinally) {
601
- if (this.prev < entry.finallyLoc) {
602
- return handle(entry.finallyLoc);
603
- }
249
+ self.resetLevel = function () {
250
+ self.setLevel(defaultLevel, false);
251
+ clearPersistedLevel();
252
+ };
604
253
 
605
- } else {
606
- throw new Error("try statement without catch or finally");
607
- }
608
- }
609
- }
610
- },
611
-
612
- abrupt: function(type, arg) {
613
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
614
- var entry = this.tryEntries[i];
615
- if (entry.tryLoc <= this.prev &&
616
- hasOwn.call(entry, "finallyLoc") &&
617
- this.prev < entry.finallyLoc) {
618
- var finallyEntry = entry;
619
- break;
620
- }
621
- }
254
+ self.disableAll = function (persist) {
255
+ self.setLevel(self.levels.SILENT, persist);
256
+ }; // Initialize with the right level
622
257
 
623
- if (finallyEntry &&
624
- (type === "break" ||
625
- type === "continue") &&
626
- finallyEntry.tryLoc <= arg &&
627
- arg <= finallyEntry.finallyLoc) {
628
- // Ignore the finally entry if control is not jumping to a
629
- // location outside the try/catch block.
630
- finallyEntry = null;
631
- }
632
258
 
633
- var record = finallyEntry ? finallyEntry.completion : {};
634
- record.type = type;
635
- record.arg = arg;
259
+ var initialLevel = getPersistedLevel();
636
260
 
637
- if (finallyEntry) {
638
- this.method = "next";
639
- this.next = finallyEntry.finallyLoc;
640
- return ContinueSentinel;
261
+ if (initialLevel == null) {
262
+ initialLevel = defaultLevel;
641
263
  }
642
264
 
643
- return this.complete(record);
644
- },
645
-
646
- complete: function(record, afterLoc) {
647
- if (record.type === "throw") {
648
- throw record.arg;
649
- }
265
+ self.setLevel(initialLevel, false);
266
+ }
267
+ /*
268
+ *
269
+ * Top-level API
270
+ *
271
+ */
650
272
 
651
- if (record.type === "break" ||
652
- record.type === "continue") {
653
- this.next = record.arg;
654
- } else if (record.type === "return") {
655
- this.rval = this.arg = record.arg;
656
- this.method = "return";
657
- this.next = "end";
658
- } else if (record.type === "normal" && afterLoc) {
659
- this.next = afterLoc;
660
- }
661
273
 
662
- return ContinueSentinel;
663
- },
274
+ var defaultLogger = new Logger();
275
+ var _loggersByName = {};
664
276
 
665
- finish: function(finallyLoc) {
666
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
667
- var entry = this.tryEntries[i];
668
- if (entry.finallyLoc === finallyLoc) {
669
- this.complete(entry.completion, entry.afterLoc);
670
- resetTryEntry(entry);
671
- return ContinueSentinel;
672
- }
673
- }
674
- },
675
-
676
- "catch": function(tryLoc) {
677
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
678
- var entry = this.tryEntries[i];
679
- if (entry.tryLoc === tryLoc) {
680
- var record = entry.completion;
681
- if (record.type === "throw") {
682
- var thrown = record.arg;
683
- resetTryEntry(entry);
684
- }
685
- return thrown;
686
- }
277
+ defaultLogger.getLogger = function getLogger(name) {
278
+ if (typeof name !== "symbol" && typeof name !== "string" || name === "") {
279
+ throw new TypeError("You must supply a name when creating a logger.");
687
280
  }
688
281
 
689
- // The context.catch method must only be called with a location
690
- // argument that corresponds to a known catch block.
691
- throw new Error("illegal catch attempt");
692
- },
282
+ var logger = _loggersByName[name];
693
283
 
694
- delegateYield: function(iterable, resultName, nextLoc) {
695
- this.delegate = {
696
- iterator: values(iterable),
697
- resultName: resultName,
698
- nextLoc: nextLoc
699
- };
700
-
701
- if (this.method === "next") {
702
- // Deliberately forget the last sent value so that we don't
703
- // accidentally pass it on to the delegate.
704
- this.arg = undefined$1;
284
+ if (!logger) {
285
+ logger = _loggersByName[name] = new Logger(name, defaultLogger.getLevel(), defaultLogger.methodFactory);
705
286
  }
706
287
 
707
- return ContinueSentinel;
708
- }
709
- };
710
-
711
- // Regardless of whether this script is executing as a CommonJS module
712
- // or not, return the runtime object so that we can declare the variable
713
- // regeneratorRuntime in the outer scope, which allows this module to be
714
- // injected easily by `bin/regenerator --include-runtime script.js`.
715
- return exports;
716
-
717
- }(
718
- // If this script is executing as a CommonJS module, use module.exports
719
- // as the regeneratorRuntime namespace. Otherwise create a new empty
720
- // object. Either way, the resulting object will be used to initialize
721
- // the regeneratorRuntime variable at the top of this file.
722
- module.exports
723
- ));
724
-
725
- try {
726
- regeneratorRuntime = runtime;
727
- } catch (accidentalStrictMode) {
728
- // This module should not be running in strict mode, so the above
729
- // assignment should always work unless something is misconfigured. Just
730
- // in case runtime.js accidentally runs in strict mode, we can escape
731
- // strict mode using a global Function call. This could conceivably fail
732
- // if a Content Security Policy forbids using Function, but in that case
733
- // the proper solution is to fix the accidental strict mode problem. If
734
- // you've misconfigured your bundler to force strict mode and applied a
735
- // CSP to forbid Function, and you're not willing to fix either of those
736
- // problems, please detail your unique predicament in a GitHub issue.
737
- Function("r", "regeneratorRuntime = r")(runtime);
738
- }
739
- });
288
+ return logger;
289
+ }; // Grab the current global log variable in case of overwrite
740
290
 
741
- var regenerator = runtime_1;
742
291
 
743
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
744
- try {
745
- var info = gen[key](arg);
746
- var value = info.value;
747
- } catch (error) {
748
- reject(error);
749
- return;
750
- }
292
+ var _log = typeof window !== undefinedType ? window.log : undefined;
751
293
 
752
- if (info.done) {
753
- resolve(value);
754
- } else {
755
- Promise.resolve(value).then(_next, _throw);
756
- }
757
- }
294
+ defaultLogger.noConflict = function () {
295
+ if (typeof window !== undefinedType && window.log === defaultLogger) {
296
+ window.log = _log;
297
+ }
758
298
 
759
- function _asyncToGenerator(fn) {
760
- return function () {
761
- var self = this,
762
- args = arguments;
763
- return new Promise(function (resolve, reject) {
764
- var gen = fn.apply(self, args);
299
+ return defaultLogger;
300
+ };
765
301
 
766
- function _next(value) {
767
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
768
- }
302
+ defaultLogger.getLoggers = function getLoggers() {
303
+ return _loggersByName;
304
+ }; // ES6 default export, for compatibility
769
305
 
770
- function _throw(err) {
771
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
772
- }
773
306
 
774
- _next(undefined);
775
- });
776
- };
777
- }
307
+ defaultLogger['default'] = defaultLogger;
308
+ return defaultLogger;
309
+ });
310
+ })(loglevel);
778
311
 
779
312
  function _defineProperty(obj, key, value) {
780
313
  if (key in obj) {
@@ -792,7 +325,7 @@
792
325
  }
793
326
 
794
327
  function _slicedToArray(arr, i) {
795
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
328
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
796
329
  }
797
330
 
798
331
  function _arrayWithHoles(arr) {
@@ -800,13 +333,17 @@
800
333
  }
801
334
 
802
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;
803
339
  var _arr = [];
804
340
  var _n = true;
805
341
  var _d = false;
806
- var _e = undefined;
342
+
343
+ var _s, _e;
807
344
 
808
345
  try {
809
- for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
346
+ for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
810
347
  _arr.push(_s.value);
811
348
 
812
349
  if (i && _arr.length === i) break;
@@ -825,26 +362,49 @@
825
362
  return _arr;
826
363
  }
827
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
+
828
382
  function _nonIterableRest() {
829
- throw new TypeError("Invalid attempt to destructure non-iterable instance");
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.");
830
384
  }
831
385
 
832
- var has = function (obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop) };
386
+ var has = function (obj, prop) {
387
+ return Object.prototype.hasOwnProperty.call(obj, prop);
388
+ };
389
+
833
390
  var isEnumerable = function (obj, prop) {
834
- return Object.prototype.propertyIsEnumerable.call(obj, prop)
391
+ return Object.prototype.propertyIsEnumerable.call(obj, prop);
835
392
  };
836
393
 
837
- function entries (obj) {
394
+ function entries(obj) {
838
395
  if (obj == null) {
839
- throw new TypeError('Cannot convert undefined or null to object')
396
+ throw new TypeError('Cannot convert undefined or null to object');
840
397
  }
398
+
841
399
  var pairs = [];
400
+
842
401
  for (var key in obj) {
843
402
  if (has(obj, key) && isEnumerable(obj, key)) {
844
403
  pairs.push([key, obj[key]]);
845
404
  }
846
405
  }
847
- return pairs
406
+
407
+ return pairs;
848
408
  }
849
409
 
850
410
  var entries_1 = entries;
@@ -902,111 +462,6 @@
902
462
 
903
463
  var reversedCommands = reverse(commands);
904
464
 
905
- /**
906
- * Postmessage legacy protocol (3.5)
907
- */
908
-
909
- var protocol = {
910
- init: 'pluginLoaded',
911
- // send this if ready to communicate
912
- platformInfo: 'platformInfo',
913
- // receive this after pluginLoaded was sent
914
- startUpload: 'startImageUploadForPlugin',
915
- // start a file upload process
916
- finishUpload: 'finishedImageUploadForPlugin' // return the file data uploaded
917
-
918
- };
919
- var invocationMapping = _defineProperty({}, commands.nativeUpload, 'nativeFileUpload');
920
-
921
- /**
922
- * Generates an unique id of 4 alpha numerical chars
923
- *
924
- * @return {string} unique id
925
- */
926
- var genID = function genID() {
927
- return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
928
- };
929
-
930
- /**
931
- * @type {Object.<string, {resolve: function, reject: function, promise: Promise}>}
932
- */
933
-
934
- var promiseMap = {};
935
- /**
936
- * Create an info object for a new promise in the map.
937
- *
938
- * @return {string} id of the promise
939
- */
940
-
941
- function createPromiseObject() {
942
- var id = genID(); // When the id is already used, it invokes the function again
943
-
944
- if (id in promiseMap) return createPromiseObject();
945
- promiseMap[id] = {
946
- resolve: null,
947
- reject: null,
948
- promise: null
949
- };
950
- return id;
951
- }
952
- /**
953
- * Create a promise and return it's id.
954
- *
955
- * The id can be used to operate on the promise using other interface functions.
956
- *
957
- * @return {string} id of the promise
958
- */
959
-
960
-
961
- var create = function create() {
962
- var id = createPromiseObject();
963
- var p = new Promise(function (resolve, reject) {
964
- promiseMap[id].resolve = resolve;
965
- promiseMap[id].reject = reject;
966
- });
967
- promiseMap[id].promise = p;
968
- return id;
969
- };
970
- /**
971
- * Resolve a promise by id.
972
- *
973
- * @param {string} id of the promise
974
- * @param {any} msg the message which will will be passed to resolve
975
- *
976
- * @throws {Error} on unknown id
977
- */
978
-
979
- var resolve = function resolve(id, msg) {
980
- if (!(id in promiseMap)) throw new Error('Tried to resolve an unknown [' + id + '] promise.');
981
- promiseMap[id].resolve(msg);
982
- delete promiseMap[id];
983
- };
984
- /**
985
- * Reject a promise by id.
986
- *
987
- * @param {string} id of the promise
988
- * @param {any} err the error which will will be passed to reject
989
- * @throws {Error} on unknown id
990
- */
991
-
992
- var reject = function reject(id, err) {
993
- if (!(id in promiseMap)) throw new Error('Tried to reject an unknown [' + id + '] promise.');
994
- promiseMap[id].reject(err);
995
- delete promiseMap[id];
996
- };
997
- /**
998
- * Get a promise by id.
999
- *
1000
- * @param {string} id of the promise
1001
- * @return {Promise} the promise identified by id
1002
- * @throws {Error} on unknown id
1003
- */
1004
-
1005
- var get = function get(id) {
1006
- if (!(id in promiseMap)) throw new Error('Tried to get an unknown [' + id + '] promise.');
1007
- return promiseMap[id].promise;
1008
- };
1009
-
1010
465
  var locales = {
1011
466
  ar: {
1012
467
  key: 'ar',
@@ -1250,7 +705,7 @@
1250
705
  */
1251
706
 
1252
707
 
1253
- var getVersion = function getVersion() {
708
+ var getVersion$1 = function getVersion() {
1254
709
  return window.Staffbase.platform.version;
1255
710
  };
1256
711
  /**
@@ -1260,9 +715,9 @@
1260
715
  * @return {Boolean}
1261
716
  */
1262
717
 
1263
- var isNative = function isNative() {
718
+ var isNative$1 = function isNative() {
1264
719
  var safari = /safari/i.test(userAgent);
1265
- return window.Staffbase.platform.native === 'android' || window.Staffbase.platform.native === 'ios' || !safari && isIos();
720
+ return window.Staffbase.platform.native === 'android' || window.Staffbase.platform.native === 'ios' || !safari && isIos$1();
1266
721
  };
1267
722
  /**
1268
723
  * Are we running on a mobile device
@@ -1270,7 +725,7 @@
1270
725
  * @return {Boolean}
1271
726
  */
1272
727
 
1273
- var isMobile = function isMobile() {
728
+ var isMobile$1 = function isMobile() {
1274
729
  return window.Staffbase.platform.mobile;
1275
730
  };
1276
731
  /**
@@ -1279,7 +734,7 @@
1279
734
  * @return {Boolean}
1280
735
  */
1281
736
 
1282
- var isAndroid = function isAndroid() {
737
+ var isAndroid$1 = function isAndroid() {
1283
738
  return window.Staffbase.platform.native === 'android' || /Android/i.test(userAgent);
1284
739
  };
1285
740
  /**
@@ -1288,7 +743,7 @@
1288
743
  * @return {Boolean}
1289
744
  */
1290
745
 
1291
- var isIos = function isIos() {
746
+ var isIos$1 = function isIos() {
1292
747
  return window.Staffbase.platform.native === 'ios' || /iPhone|iPad|iPod/i.test(userAgent);
1293
748
  };
1294
749
  /**
@@ -1297,7 +752,7 @@
1297
752
  * @param {String} url address
1298
753
  */
1299
754
 
1300
- var openLink = function openLink(url) {
755
+ var openLink$2 = function openLink(url) {
1301
756
  window.open(url, '_blank');
1302
757
  };
1303
758
  /**
@@ -1317,7 +772,7 @@
1317
772
  */
1318
773
 
1319
774
  var langInfos = function langInfos() {
1320
- var branchDefaultLanguage = getBranchDefaultLanguage();
775
+ var branchDefaultLanguage = getBranchDefaultLanguage$2();
1321
776
  return {
1322
777
  contentLanguage: branchDefaultLanguage,
1323
778
  branchLanguages: locales,
@@ -1332,7 +787,7 @@
1332
787
  * @return {Object} the language object
1333
788
  */
1334
789
 
1335
- var getBranchDefaultLanguage = function getBranchDefaultLanguage() {
790
+ var getBranchDefaultLanguage$2 = function getBranchDefaultLanguage() {
1336
791
  return locales[currentLanguage] || locales.en;
1337
792
  };
1338
793
  /**
@@ -1343,8 +798,8 @@
1343
798
  * @return {string}
1344
799
  */
1345
800
 
1346
- var getPreferredContentLocale = function getPreferredContentLocale(content) {
1347
- var locale = getBranchDefaultLanguage().locale;
801
+ var getPreferredContentLocale$2 = function getPreferredContentLocale(content) {
802
+ var locale = getBranchDefaultLanguage$2().locale;
1348
803
 
1349
804
  if (!content) {
1350
805
  return locale;
@@ -1362,7 +817,7 @@
1362
817
  }
1363
818
  };
1364
819
 
1365
- var connection = null;
820
+ var connection$2 = null;
1366
821
  var fallbackKickIn = 500;
1367
822
  /**
1368
823
  * Fake connection to the Staffbase App after a period of time.
@@ -1373,16 +828,16 @@
1373
828
  */
1374
829
 
1375
830
  var fallback = (function () {
1376
- if (connection) {
1377
- return connection;
831
+ if (connection$2) {
832
+ return connection$2;
1378
833
  }
1379
834
 
1380
- connection = new Promise(function (resolve, reject) {
835
+ connection$2 = new Promise(function (resolve) {
1381
836
  setTimeout(function () {
1382
- resolve(sendMessage);
837
+ resolve(sendMessage$3);
1383
838
  }, fallbackKickIn);
1384
839
  });
1385
- return connection;
840
+ return connection$2;
1386
841
  });
1387
842
  /**
1388
843
  * Send a SDK command to the Staffbase App.
@@ -1394,260 +849,159 @@
1394
849
  * @throws {Error} on commands not supported by protocol
1395
850
  */
1396
851
 
1397
- var sendMessage =
1398
- /*#__PURE__*/
1399
- function () {
1400
- var _ref = _asyncToGenerator(
1401
- /*#__PURE__*/
1402
- regenerator.mark(function _callee(cmd) {
1403
- var _len,
1404
- payload,
1405
- _key,
1406
- _args = arguments;
1407
-
1408
- return regenerator.wrap(function _callee$(_context) {
1409
- while (1) {
1410
- switch (_context.prev = _context.next) {
1411
- case 0:
1412
- for (_len = _args.length, payload = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1413
- payload[_key - 1] = _args[_key];
1414
- }
852
+ var sendMessage$3 = function sendMessage(cmd) {
853
+ var $args = arguments;
854
+ return new Promise(function ($return, $error) {
855
+ for (var _len = $args.length, payload = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
856
+ payload[_key - 1] = $args[_key];
857
+ }
1415
858
 
1416
- _context.t0 = cmd;
1417
- _context.next = _context.t0 === commands.version ? 4 : _context.t0 === commands.native ? 5 : _context.t0 === commands.mobile ? 6 : _context.t0 === commands.ios ? 7 : _context.t0 === commands.android ? 8 : _context.t0 === commands.openLink ? 9 : _context.t0 === commands.langInfos ? 10 : _context.t0 === commands.branchDefaultLang ? 11 : _context.t0 === commands.prefContentLang ? 12 : _context.t0 === commands.nativeUpload ? 13 : _context.t0 === commands.nativeShare ? 13 : 14;
1418
- break;
859
+ switch (cmd) {
860
+ case commands.version:
861
+ return $return(getVersion$1());
1419
862
 
1420
- case 4:
1421
- return _context.abrupt("return", getVersion());
863
+ case commands.native:
864
+ return $return(isNative$1());
1422
865
 
1423
- case 5:
1424
- return _context.abrupt("return", isNative());
866
+ case commands.mobile:
867
+ return $return(isMobile$1());
1425
868
 
1426
- case 6:
1427
- return _context.abrupt("return", isMobile());
869
+ case commands.ios:
870
+ return $return(isIos$1());
1428
871
 
1429
- case 7:
1430
- return _context.abrupt("return", isIos());
872
+ case commands.android:
873
+ return $return(isAndroid$1());
1431
874
 
1432
- case 8:
1433
- return _context.abrupt("return", isAndroid());
875
+ case commands.openLink:
876
+ return $return(openLink$2.apply(null, payload));
1434
877
 
1435
- case 9:
1436
- return _context.abrupt("return", openLink.apply(null, payload));
878
+ case commands.langInfos:
879
+ return $return(langInfos());
1437
880
 
1438
- case 10:
1439
- return _context.abrupt("return", langInfos());
881
+ case commands.branchDefaultLang:
882
+ return $return(getBranchDefaultLanguage$2());
1440
883
 
1441
- case 11:
1442
- return _context.abrupt("return", getBranchDefaultLanguage());
884
+ case commands.prefContentLang:
885
+ return $return(getPreferredContentLocale$2.apply(null, payload));
1443
886
 
1444
- case 12:
1445
- return _context.abrupt("return", getPreferredContentLocale.apply(null, payload));
887
+ case commands.nativeUpload:
888
+ case commands.nativeShare:
889
+ return $return(unSupported());
1446
890
 
1447
- case 13:
1448
- return _context.abrupt("return", unSupported());
891
+ default:
892
+ // should actually never ever happen
893
+ return $error(new Error('Command ' + cmd + ' not supported by driver'));
894
+ }
1449
895
 
1450
- case 14:
1451
- throw new Error('Command ' + cmd + ' not supported by driver');
896
+ return $return();
897
+ });
898
+ };
1452
899
 
1453
- case 15:
1454
- case "end":
1455
- return _context.stop();
1456
- }
1457
- }
1458
- }, _callee);
1459
- }));
900
+ var _invocationMapping;
901
+ /**
902
+ * Postmessage protocol (3.6)
903
+ */
1460
904
 
1461
- return function sendMessage(_x) {
1462
- return _ref.apply(this, arguments);
1463
- };
1464
- }();
905
+ var protocol = {
906
+ HELLO: 'HELLO',
907
+ // send this if ready to communicate
908
+ SUCCESS: 'SUCCESS',
909
+ // receive this after pluginLoaded was sent
910
+ INVOCATION: 'INVOCATION',
911
+ // send this to call a function in the frontend
912
+ ERROR: 'ERROR' // receive this when something goes wrong
913
+
914
+ };
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);
1465
916
 
1466
- var connection$1 = null;
1467
- var connectId = null;
1468
- var targetOrigin = '*';
1469
917
  /**
1470
- * @typedef {{ mobile: boolean, version: string|number, native: string }} PlatformInfos
1471
- * @typedef {{ mobile: boolean, version: string|number, native: string, ios: boolean, android: boolean }} StaticValueStore
918
+ * Generates an unique id of 4 alpha numerical chars
919
+ *
920
+ * @return {string} unique id
1472
921
  */
922
+ var genID = function genID() {
923
+ return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
924
+ };
1473
925
 
1474
926
  /**
1475
- * Simple store solution to make the initial data available
1476
- * as static values
927
+ * @type {Object.<string, {resolve: function, reject: function, promise: Promise}>}
928
+ */
929
+
930
+ var promiseMap = {};
931
+ /**
932
+ * Create an info object for a new promise in the map.
1477
933
  *
1478
- * @param {PlatformInfos} initial the initial data from the frontend
1479
- * @static
1480
- * @return {StaticValueStore}
934
+ * @return {string} id of the promise
1481
935
  */
1482
936
 
1483
- var dataStore = function dataStore(initial) {
1484
- return {
1485
- mobile: initial.mobile,
1486
- version: initial.version,
1487
- native: !!initial.native,
1488
- ios: initial.native === 'ios',
1489
- android: initial.native === 'android'
937
+ function createPromiseObject() {
938
+ var id = genID(); // When the id is already used, it invokes the function again
939
+
940
+ if (id in promiseMap) return createPromiseObject();
941
+ promiseMap[id] = {
942
+ resolve: null,
943
+ reject: null,
944
+ promise: null
1490
945
  };
1491
- };
946
+ return id;
947
+ }
1492
948
  /**
1493
- * Connect to the Staffbase App.
949
+ * Create a promise and return it's id.
1494
950
  *
1495
- * Create a connection to a Staffbase app 3.5
1496
- * @return {Promise<function>} An appropriate send function
951
+ * The id can be used to operate on the promise using other interface functions.
952
+ *
953
+ * @return {string} id of the promise
1497
954
  */
1498
955
 
1499
956
 
1500
- var connect = function connect() {
1501
- if (connection$1) {
1502
- return connection$1;
1503
- }
1504
-
1505
- connectId = create();
1506
- connection$1 = get(connectId).then(function (payload) {
1507
- return sendMessage$1(dataStore(payload));
957
+ var create = function create() {
958
+ var id = createPromiseObject();
959
+ var p = new Promise(function (resolve, reject) {
960
+ promiseMap[id].resolve = resolve;
961
+ promiseMap[id].reject = reject;
1508
962
  });
1509
- window.addEventListener('message', receiveMessage);
1510
- window.parent.postMessage(protocol.init, targetOrigin);
1511
- return connection$1;
963
+ promiseMap[id].promise = p;
964
+ return id;
1512
965
  };
1513
966
  /**
1514
- * Handler that receives a message from the Staffbase app
967
+ * Resolve a promise by id.
1515
968
  *
1516
- * Can be attached to window.onPostMessage
1517
- * @param {Object} an onPostMessage event result
1518
- */
1519
-
1520
- var receiveMessage =
1521
- /*#__PURE__*/
1522
- function () {
1523
- var _ref2 = _asyncToGenerator(
1524
- /*#__PURE__*/
1525
- regenerator.mark(function _callee(_ref) {
1526
- var _ref$data, data;
1527
-
1528
- return regenerator.wrap(function _callee$(_context) {
1529
- while (1) {
1530
- switch (_context.prev = _context.next) {
1531
- case 0:
1532
- _ref$data = _ref.data, data = _ref$data === void 0 ? {} : _ref$data;
1533
- _context.t0 = data.state;
1534
- _context.next = _context.t0 === protocol.platformInfo ? 4 : _context.t0 === protocol.finishUpload ? 6 : 8;
1535
- break;
1536
-
1537
- case 4:
1538
- resolve(connectId, data.info);
1539
- return _context.abrupt("break", 9);
1540
-
1541
- case 6:
1542
- resolve(connectId, data.file);
1543
- return _context.abrupt("break", 9);
1544
-
1545
- case 8:
1546
- return _context.abrupt("return");
1547
-
1548
- case 9:
1549
- case "end":
1550
- return _context.stop();
1551
- }
1552
- }
1553
- }, _callee);
1554
- }));
1555
-
1556
- return function receiveMessage(_x) {
1557
- return _ref2.apply(this, arguments);
1558
- };
1559
- }();
1560
- /**
1561
- * Send a SDK command to the Staffbase App.
969
+ * @param {string} id of the promise
970
+ * @param {any} msg the message which will will be passed to resolve
1562
971
  *
1563
- * Translates SDK commands into protocol native commands.
1564
- * @param {StaticValueStore} store the store object
1565
- * @param {String} cmd an SDK command
1566
- * @param {array} payload for the command
1567
- * @return {Promise<any>} which awaits the response of the Staffbase App
1568
- * @throws {Error} on commands not supported by protocol
972
+ * @throws {Error} on unknown id
1569
973
  */
1570
974
 
1571
-
1572
- var sendMessage$1 = function sendMessage$1(store) {
1573
- return (
1574
- /*#__PURE__*/
1575
- function () {
1576
- var _ref3 = _asyncToGenerator(
1577
- /*#__PURE__*/
1578
- regenerator.mark(function _callee2(cmd) {
1579
- var _len,
1580
- payload,
1581
- _key,
1582
- _args2 = arguments;
1583
-
1584
- return regenerator.wrap(function _callee2$(_context2) {
1585
- while (1) {
1586
- switch (_context2.prev = _context2.next) {
1587
- case 0:
1588
- for (_len = _args2.length, payload = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1589
- payload[_key - 1] = _args2[_key];
1590
- }
1591
-
1592
- _context2.t0 = cmd;
1593
- _context2.next = _context2.t0 === commands.version ? 4 : _context2.t0 === commands.native ? 4 : _context2.t0 === commands.mobile ? 4 : _context2.t0 === commands.ios ? 4 : _context2.t0 === commands.android ? 4 : _context2.t0 === commands.nativeUpload ? 5 : 6;
1594
- break;
1595
-
1596
- case 4:
1597
- return _context2.abrupt("return", store[reversedCommands[cmd]]);
1598
-
1599
- case 5:
1600
- return _context2.abrupt("return", sendInvocationCall(invocationMapping[cmd]));
1601
-
1602
- case 6:
1603
- return _context2.abrupt("return", sendMessage.apply(null, [cmd].concat(payload)));
1604
-
1605
- case 7:
1606
- case "end":
1607
- return _context2.stop();
1608
- }
1609
- }
1610
- }, _callee2);
1611
- }));
1612
-
1613
- return function (_x2) {
1614
- return _ref3.apply(this, arguments);
1615
- };
1616
- }()
1617
- );
975
+ var resolve = function resolve(id, msg) {
976
+ if (!(id in promiseMap)) throw new Error('Tried to resolve an unknown [' + id + '] promise.');
977
+ promiseMap[id].resolve(msg);
978
+ delete promiseMap[id];
1618
979
  };
1619
980
  /**
1620
- * Create a promise and send an invocation call to the frontend
1621
- *
1622
- * @param {string} process the name of the process to call
1623
- * @param {array} args an array of arguments
981
+ * Reject a promise by id.
1624
982
  *
1625
- * @return {Promise}
983
+ * @param {string} id of the promise
984
+ * @param {any} err the error which will will be passed to reject
985
+ * @throws {Error} on unknown id
1626
986
  */
1627
987
 
1628
-
1629
- var sendInvocationCall = function sendInvocationCall(process, args) {
1630
- connectId = create();
1631
- window.parent.postMessage(protocol.startUpload, targetOrigin);
1632
- return get(connectId);
988
+ var reject = function reject(id, err) {
989
+ if (!(id in promiseMap)) throw new Error('Tried to reject an unknown [' + id + '] promise.');
990
+ promiseMap[id].reject(err);
991
+ delete promiseMap[id];
1633
992
  };
1634
-
1635
- var _invocationMapping;
1636
993
  /**
1637
- * Postmessage protocol (3.6)
994
+ * Get a promise by id.
995
+ *
996
+ * @param {string} id of the promise
997
+ * @return {Promise} the promise identified by id
998
+ * @throws {Error} on unknown id
1638
999
  */
1639
1000
 
1640
- var protocol$1 = {
1641
- HELLO: 'HELLO',
1642
- // send this if ready to communicate
1643
- SUCCESS: 'SUCCESS',
1644
- // receive this after pluginLoaded was sent
1645
- INVOCATION: 'INVOCATION',
1646
- // send this to call a function in the frontend
1647
- ERROR: 'ERROR' // receive this when something goes wrong
1648
-
1001
+ var get = function get(id) {
1002
+ if (!(id in promiseMap)) throw new Error('Tried to get an unknown [' + id + '] promise.');
1003
+ return promiseMap[id].promise;
1649
1004
  };
1650
- var invocationMapping$1 = (_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);
1651
1005
 
1652
1006
  /**
1653
1007
  * @typedef {{ mobile: boolean, version: string|number, native: string }} PlatformInfos
@@ -1682,8 +1036,8 @@
1682
1036
  };
1683
1037
  };
1684
1038
 
1685
- var connection$2 = null;
1686
- var targetOrigin$1 = '*';
1039
+ var connection$1 = null;
1040
+ var targetOrigin = '*';
1687
1041
  /**
1688
1042
  * Connect to the Staffbase App.
1689
1043
  *
@@ -1691,18 +1045,18 @@
1691
1045
  * @return {Promise<function>} An appropriate send function
1692
1046
  */
1693
1047
 
1694
- var connect$1 = function connect() {
1695
- if (connection$2) {
1696
- return connection$2;
1048
+ var connect$2 = function connect() {
1049
+ if (connection$1) {
1050
+ return connection$1;
1697
1051
  }
1698
1052
 
1699
1053
  var connectId = create();
1700
- connection$2 = get(connectId).then(function (payload) {
1054
+ connection$1 = get(connectId).then(function (payload) {
1701
1055
  return sendMessage$2(dataStore$1(payload));
1702
1056
  });
1703
- window.addEventListener('message', receiveMessage$1);
1704
- window.parent.postMessage([protocol$1.HELLO, connectId, []], targetOrigin$1);
1705
- return connection$2;
1057
+ window.addEventListener('message', receiveMessage);
1058
+ window.parent.postMessage([protocol.HELLO, connectId, []], targetOrigin);
1059
+ return connection$1;
1706
1060
  };
1707
1061
  /**
1708
1062
  * Handler that receives a message from the Staffbase app
@@ -1711,59 +1065,46 @@
1711
1065
  * @param {MessageEvent} evt onPostMessage event result
1712
1066
  */
1713
1067
 
1714
- var receiveMessage$1 =
1715
- /*#__PURE__*/
1716
- function () {
1717
- var _ref2 = _asyncToGenerator(
1718
- /*#__PURE__*/
1719
- regenerator.mark(function _callee(evt) {
1720
- var type, id, payload, _evt$data;
1721
-
1722
- return regenerator.wrap(function _callee$(_context) {
1723
- while (1) {
1724
- switch (_context.prev = _context.next) {
1725
- case 0:
1726
- _context.prev = 0;
1727
- _evt$data = _slicedToArray(evt.data, 3);
1728
- type = _evt$data[0];
1729
- id = _evt$data[1];
1730
- payload = _evt$data[2];
1731
- _context.next = 10;
1732
- break;
1733
-
1734
- case 7:
1735
- _context.prev = 7;
1736
- _context.t0 = _context["catch"](0);
1737
- return _context.abrupt("return");
1738
-
1739
- case 10:
1740
- _context.t1 = type;
1741
- _context.next = _context.t1 === protocol$1.SUCCESS ? 13 : _context.t1 === protocol$1.ERROR ? 15 : 17;
1742
- break;
1743
-
1744
- case 13:
1745
- resolve(id, payload);
1746
- return _context.abrupt("break", 18);
1747
-
1748
- case 15:
1749
- reject(id, payload);
1750
- return _context.abrupt("break", 18);
1751
-
1752
- case 17:
1753
- return _context.abrupt("return");
1754
-
1755
- case 18:
1756
- case "end":
1757
- return _context.stop();
1758
- }
1759
- }
1760
- }, _callee, null, [[0, 7]]);
1761
- }));
1068
+ var receiveMessage = function receiveMessage(evt) {
1069
+ return new Promise(function ($return, $error) {
1070
+ var type;
1071
+ var id;
1072
+ var payload; // safe destructure
1762
1073
 
1763
- return function receiveMessage(_x) {
1764
- return _ref2.apply(this, arguments);
1765
- };
1766
- }();
1074
+ try {
1075
+ var _evt$data = _slicedToArray(evt.data, 3);
1076
+
1077
+ type = _evt$data[0];
1078
+ id = _evt$data[1];
1079
+ payload = _evt$data[2];
1080
+ } catch (e) {
1081
+ // even thought catch-ignore is a bad style
1082
+ // there may be other participants listening
1083
+ // to messages in a different format so we
1084
+ // silently ignore here
1085
+ return $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
+ });
1107
+ };
1767
1108
  /**
1768
1109
  * Send a SDK command to the Staffbase App.
1769
1110
  *
@@ -1777,51 +1118,36 @@
1777
1118
 
1778
1119
 
1779
1120
  var sendMessage$2 = function sendMessage(store) {
1780
- return (
1781
- /*#__PURE__*/
1782
- function () {
1783
- var _ref3 = _asyncToGenerator(
1784
- /*#__PURE__*/
1785
- regenerator.mark(function _callee2(cmd) {
1786
- var _len,
1787
- payload,
1788
- _key,
1789
- _args2 = arguments;
1790
-
1791
- return regenerator.wrap(function _callee2$(_context2) {
1792
- while (1) {
1793
- switch (_context2.prev = _context2.next) {
1794
- case 0:
1795
- _context2.t0 = cmd;
1796
- _context2.next = _context2.t0 === commands.version ? 3 : _context2.t0 === commands.native ? 3 : _context2.t0 === commands.mobile ? 3 : _context2.t0 === commands.ios ? 3 : _context2.t0 === commands.android ? 3 : _context2.t0 === commands.branchDefaultLang ? 3 : _context2.t0 === commands.langInfos ? 4 : _context2.t0 === commands.openLink ? 4 : _context2.t0 === commands.nativeUpload ? 4 : _context2.t0 === commands.nativeShare ? 4 : _context2.t0 === commands.prefContentLang ? 4 : 6;
1797
- break;
1798
-
1799
- case 3:
1800
- return _context2.abrupt("return", store[reversedCommands[cmd]]);
1801
-
1802
- case 4:
1803
- for (_len = _args2.length, payload = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1804
- payload[_key - 1] = _args2[_key];
1805
- }
1806
-
1807
- return _context2.abrupt("return", sendInvocationCall$1(create())(invocationMapping$1[cmd], payload));
1808
-
1809
- case 6:
1810
- throw new Error('Command ' + cmd + ' not supported by driver');
1811
-
1812
- case 7:
1813
- case "end":
1814
- return _context2.stop();
1815
- }
1121
+ return function (cmd) {
1122
+ var $args = arguments;
1123
+ return new Promise(function ($return, $error) {
1124
+ switch (cmd) {
1125
+ case commands.version:
1126
+ case commands.native:
1127
+ case commands.mobile:
1128
+ case commands.ios:
1129
+ case commands.android:
1130
+ case commands.branchDefaultLang:
1131
+ return $return(store[reversedCommands[cmd]]);
1132
+
1133
+ case commands.langInfos:
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];
1816
1140
  }
1817
- }, _callee2);
1818
- }));
1819
1141
 
1820
- return function (_x2) {
1821
- return _ref3.apply(this, arguments);
1822
- };
1823
- }()
1824
- );
1142
+ return $return(sendInvocationCall$1(create())(invocationMapping[cmd], payload));
1143
+
1144
+ default:
1145
+ return $error(new Error('Command ' + cmd + ' not supported by driver'));
1146
+ }
1147
+
1148
+ return $return();
1149
+ });
1150
+ };
1825
1151
  };
1826
1152
  /**
1827
1153
  * Create a promise and send an invocation call to the frontend
@@ -1836,12 +1162,12 @@
1836
1162
 
1837
1163
  var sendInvocationCall$1 = function sendInvocationCall(promiseID) {
1838
1164
  return function (process, args) {
1839
- window.parent.postMessage([protocol$1.INVOCATION, promiseID, process, args], targetOrigin$1);
1165
+ window.parent.postMessage([protocol.INVOCATION, promiseID, process, args], targetOrigin);
1840
1166
  return get(promiseID);
1841
1167
  };
1842
1168
  };
1843
1169
 
1844
- var connection$3 = null;
1170
+ var connection = null;
1845
1171
  var outMsgQueue = [];
1846
1172
  /**
1847
1173
  * Simple store solution to make the initial data available
@@ -1852,7 +1178,7 @@
1852
1178
  * @return {StaticValueStore}
1853
1179
  */
1854
1180
 
1855
- var dataStore$2 = function dataStore(_ref) {
1181
+ var dataStore = function dataStore(_ref) {
1856
1182
  var platform = _ref.platform,
1857
1183
  language = _ref.language;
1858
1184
  return {
@@ -1878,17 +1204,17 @@
1878
1204
  * @return {Promise<function>} An appropriate send function
1879
1205
  */
1880
1206
 
1881
- var connect$2 = function connect() {
1882
- if (connection$3) {
1883
- return connection$3;
1207
+ var connect$1 = function connect() {
1208
+ if (connection) {
1209
+ return connection;
1884
1210
  }
1885
1211
 
1886
1212
  var connectId = create();
1887
- connection$3 = get(connectId).then(function (payload) {
1888
- return sendMessage$3(dataStore$2(payload));
1213
+ connection = get(connectId).then(function (payload) {
1214
+ return sendMessage$1(dataStore(payload));
1889
1215
  });
1890
- outMsgQueue.push([protocol$1.HELLO, connectId, []]);
1891
- return connection$3;
1216
+ outMsgQueue.push([protocol.HELLO, connectId, []]);
1217
+ return connection;
1892
1218
  };
1893
1219
  /**
1894
1220
  * A function which returns an array of messages
@@ -1928,11 +1254,11 @@
1928
1254
  payload = _msg[2];
1929
1255
 
1930
1256
  switch (type) {
1931
- case protocol$1.SUCCESS:
1257
+ case protocol.SUCCESS:
1932
1258
  resolve(id, payload);
1933
1259
  break;
1934
1260
 
1935
- case protocol$1.ERROR:
1261
+ case protocol.ERROR:
1936
1262
  reject(id, payload);
1937
1263
  break;
1938
1264
 
@@ -1962,52 +1288,35 @@
1962
1288
  * @throws {Error} on commands not supported by protocol
1963
1289
  */
1964
1290
 
1965
- var sendMessage$3 = function sendMessage(store) {
1966
- return (
1967
- /*#__PURE__*/
1968
- function () {
1969
- var _ref2 = _asyncToGenerator(
1970
- /*#__PURE__*/
1971
- regenerator.mark(function _callee(cmd) {
1972
- var _len,
1973
- payload,
1974
- _key,
1975
- _args = arguments;
1976
-
1977
- return regenerator.wrap(function _callee$(_context) {
1978
- while (1) {
1979
- switch (_context.prev = _context.next) {
1980
- case 0:
1981
- _context.t0 = cmd;
1982
- _context.next = _context.t0 === commands.version ? 3 : _context.t0 === commands.native ? 3 : _context.t0 === commands.mobile ? 3 : _context.t0 === commands.ios ? 3 : _context.t0 === commands.android ? 3 : _context.t0 === commands.langInfos ? 3 : _context.t0 === commands.branchDefaultLang ? 3 : _context.t0 === commands.openLink ? 4 : _context.t0 === commands.prefContentLang ? 4 : 6;
1983
- break;
1984
-
1985
- case 3:
1986
- return _context.abrupt("return", store[reversedCommands[cmd]]);
1987
-
1988
- case 4:
1989
- for (_len = _args.length, payload = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1990
- payload[_key - 1] = _args[_key];
1991
- }
1992
-
1993
- return _context.abrupt("return", sendInvocationCall$2(invocationMapping$1[cmd], payload));
1994
-
1995
- case 6:
1996
- throw new Error('Command ' + cmd + ' not supported by driver');
1997
-
1998
- case 7:
1999
- case "end":
2000
- return _context.stop();
2001
- }
1291
+ var sendMessage$1 = function sendMessage(store) {
1292
+ return function (cmd) {
1293
+ var $args = arguments;
1294
+ return new Promise(function ($return, $error) {
1295
+ switch (cmd) {
1296
+ case commands.version:
1297
+ case commands.native:
1298
+ case commands.mobile:
1299
+ case commands.ios:
1300
+ case commands.android:
1301
+ case commands.langInfos:
1302
+ case commands.branchDefaultLang:
1303
+ return $return(store[reversedCommands[cmd]]);
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];
2002
1309
  }
2003
- }, _callee);
2004
- }));
2005
1310
 
2006
- return function (_x) {
2007
- return _ref2.apply(this, arguments);
2008
- };
2009
- }()
2010
- );
1311
+ return $return(sendInvocationCall(invocationMapping[cmd], payload));
1312
+
1313
+ default:
1314
+ return $error(new Error('Command ' + cmd + ' not supported by driver'));
1315
+ }
1316
+
1317
+ return $return();
1318
+ });
1319
+ };
2011
1320
  };
2012
1321
  /**
2013
1322
  * Create a promise and send an invocation call to the frontend
@@ -2019,53 +1328,29 @@
2019
1328
  */
2020
1329
 
2021
1330
 
2022
- var sendInvocationCall$2 = function sendInvocationCall(process, args) {
1331
+ var sendInvocationCall = function sendInvocationCall(process, args) {
2023
1332
  var promiseID = create();
2024
- outMsgQueue.push([protocol$1.INVOCATION, promiseID, process, args]);
1333
+ outMsgQueue.push([protocol.INVOCATION, promiseID, process, args]);
2025
1334
  return get(promiseID);
2026
1335
  };
2027
1336
 
2028
1337
  var connector;
2029
1338
 
2030
- var connect$3 =
2031
- /*#__PURE__*/
2032
- function () {
2033
- var _ref = _asyncToGenerator(
2034
- /*#__PURE__*/
2035
- regenerator.mark(function _callee() {
2036
- var putMessageConnection, postMessageConnection, postMessagLegacyConnection, fallbackConnection, realConnectionBucket, fallbackConnectionBucket;
2037
- return regenerator.wrap(function _callee$(_context) {
2038
- while (1) {
2039
- switch (_context.prev = _context.next) {
2040
- case 0:
2041
- putMessageConnection = connect$2();
2042
- postMessageConnection = connect$1();
2043
- postMessagLegacyConnection = connect();
2044
- fallbackConnection = fallback();
2045
- realConnectionBucket = [putMessageConnection, postMessageConnection, postMessagLegacyConnection];
2046
- fallbackConnectionBucket = realConnectionBucket.concat(fallbackConnection); // Wait on the real communication and replace the connector with
2047
-
2048
- Promise.race(realConnectionBucket).then(function (newConnector) {
2049
- connector = newConnector;
2050
- });
2051
- _context.next = 9;
2052
- return Promise.race(fallbackConnectionBucket);
2053
-
2054
- case 9:
2055
- return _context.abrupt("return", _context.sent);
2056
-
2057
- case 10:
2058
- case "end":
2059
- return _context.stop();
2060
- }
2061
- }
2062
- }, _callee);
2063
- }));
2064
-
2065
- return function connect() {
2066
- return _ref.apply(this, arguments);
2067
- };
2068
- }();
1339
+ var connect = function connect() {
1340
+ return new Promise(function ($return, $error) {
1341
+ var putMessageConnection, postMessageConnection, fallbackConnection, realConnectionBucket, fallbackConnectionBucket;
1342
+ putMessageConnection = connect$1();
1343
+ postMessageConnection = connect$2();
1344
+ fallbackConnection = fallback();
1345
+ realConnectionBucket = [putMessageConnection, postMessageConnection];
1346
+ fallbackConnectionBucket = realConnectionBucket.concat(fallbackConnection);
1347
+ // Wait on the real communication and replace the connector with
1348
+ Promise.race(realConnectionBucket).then(function (newConnector) {
1349
+ connector = newConnector;
1350
+ });
1351
+ return Promise.resolve(Promise.race(fallbackConnectionBucket)).then($return, $error);
1352
+ });
1353
+ };
2069
1354
  /**
2070
1355
  * Send a message to the App
2071
1356
  *
@@ -2077,50 +1362,30 @@
2077
1362
  * @return {Promise<any>} result of the request
2078
1363
  */
2079
1364
 
2080
- var sendMessage$4 =
2081
- /*#__PURE__*/
2082
- function () {
2083
- var _ref2 = _asyncToGenerator(
2084
- /*#__PURE__*/
2085
- regenerator.mark(function _callee2(msg) {
2086
- var sendFn,
2087
- _len,
2088
- payload,
2089
- _key,
2090
- _args2 = arguments;
2091
-
2092
- return regenerator.wrap(function _callee2$(_context2) {
2093
- while (1) {
2094
- switch (_context2.prev = _context2.next) {
2095
- case 0:
2096
- if (!connector) {
2097
- connector = connect$3();
2098
- }
2099
-
2100
- _context2.next = 3;
2101
- return connector;
1365
+ var sendMessage = function sendMessage(msg) {
1366
+ var $args = arguments;
1367
+ return new Promise(function ($return, $error) {
1368
+ var sendFn, _len, payload, _key;
2102
1369
 
2103
- case 3:
2104
- sendFn = _context2.sent;
2105
-
2106
- for (_len = _args2.length, payload = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
2107
- payload[_key - 1] = _args2[_key];
2108
- }
1370
+ if (!connector) {
1371
+ connector = connect();
1372
+ }
2109
1373
 
2110
- return _context2.abrupt("return", sendFn.apply(void 0, [msg].concat(payload)));
1374
+ return Promise.resolve(connector).then(function ($await_2) {
1375
+ try {
1376
+ sendFn = $await_2;
2111
1377
 
2112
- case 6:
2113
- case "end":
2114
- return _context2.stop();
1378
+ for (_len = $args.length, payload = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1379
+ payload[_key - 1] = $args[_key];
2115
1380
  }
2116
- }
2117
- }, _callee2);
2118
- }));
2119
1381
 
2120
- return function sendMessage(_x) {
2121
- return _ref2.apply(this, arguments);
2122
- };
2123
- }();
1382
+ return $return(sendFn.apply(void 0, [msg].concat(payload)));
1383
+ } catch ($boundEx) {
1384
+ return $error($boundEx);
1385
+ }
1386
+ }, $error);
1387
+ });
1388
+ };
2124
1389
 
2125
1390
  /**
2126
1391
  * Get the version of the Staffbase App.
@@ -2128,90 +1393,33 @@
2128
1393
  * @return {Promise<string>}
2129
1394
  */
2130
1395
 
2131
- var getVersion$1 =
2132
- /*#__PURE__*/
2133
- function () {
2134
- var _ref = _asyncToGenerator(
2135
- /*#__PURE__*/
2136
- regenerator.mark(function _callee() {
2137
- return regenerator.wrap(function _callee$(_context) {
2138
- while (1) {
2139
- switch (_context.prev = _context.next) {
2140
- case 0:
2141
- return _context.abrupt("return", sendMessage$4(commands.version));
2142
-
2143
- case 1:
2144
- case "end":
2145
- return _context.stop();
2146
- }
2147
- }
2148
- }, _callee);
2149
- }));
2150
-
2151
- return function getVersion() {
2152
- return _ref.apply(this, arguments);
2153
- };
2154
- }();
1396
+ var getVersion = function getVersion() {
1397
+ return new Promise(function ($return, $error) {
1398
+ return $return(sendMessage(commands.version));
1399
+ });
1400
+ };
2155
1401
  /**
2156
1402
  * Check if app is native.
2157
1403
  *
2158
1404
  * @return {Promise<boolean>}
2159
1405
  */
2160
1406
 
2161
- var isNative$1 =
2162
- /*#__PURE__*/
2163
- function () {
2164
- var _ref2 = _asyncToGenerator(
2165
- /*#__PURE__*/
2166
- regenerator.mark(function _callee2() {
2167
- return regenerator.wrap(function _callee2$(_context2) {
2168
- while (1) {
2169
- switch (_context2.prev = _context2.next) {
2170
- case 0:
2171
- return _context2.abrupt("return", sendMessage$4(commands.native));
2172
-
2173
- case 1:
2174
- case "end":
2175
- return _context2.stop();
2176
- }
2177
- }
2178
- }, _callee2);
2179
- }));
2180
-
2181
- return function isNative() {
2182
- return _ref2.apply(this, arguments);
2183
- };
2184
- }();
1407
+ var isNative = function isNative() {
1408
+ return new Promise(function ($return, $error) {
1409
+ return $return(sendMessage(commands.native));
1410
+ });
1411
+ };
2185
1412
  /**
2186
1413
  * Check if app is mobile.
2187
1414
  *
2188
1415
  * @return {Promise<boolean>}
2189
1416
  */
2190
1417
 
2191
- var isMobile$1 =
2192
- /*#__PURE__*/
2193
- function () {
2194
- var _ref3 = _asyncToGenerator(
2195
- /*#__PURE__*/
2196
- regenerator.mark(function _callee3() {
2197
- return regenerator.wrap(function _callee3$(_context3) {
2198
- while (1) {
2199
- switch (_context3.prev = _context3.next) {
2200
- case 0:
2201
- return _context3.abrupt("return", sendMessage$4(commands.mobile));
2202
-
2203
- case 1:
2204
- case "end":
2205
- return _context3.stop();
2206
- }
2207
- }
2208
- }, _callee3);
2209
- }));
2210
-
2211
- return function isMobile() {
2212
- return _ref3.apply(this, arguments);
2213
- };
2214
- }();
1418
+ var isMobile = function isMobile() {
1419
+ return new Promise(function ($return, $error) {
1420
+ return $return(sendMessage(commands.mobile));
1421
+ });
1422
+ };
2215
1423
  /**
2216
1424
  * Open a link through the app.
2217
1425
  *
@@ -2223,30 +1431,11 @@
2223
1431
  * @return {Promise<any>}
2224
1432
  */
2225
1433
 
2226
- var openLink$1 =
2227
- /*#__PURE__*/
2228
- function () {
2229
- var _ref4 = _asyncToGenerator(
2230
- /*#__PURE__*/
2231
- regenerator.mark(function _callee4(url) {
2232
- return regenerator.wrap(function _callee4$(_context4) {
2233
- while (1) {
2234
- switch (_context4.prev = _context4.next) {
2235
- case 0:
2236
- return _context4.abrupt("return", sendMessage$4(commands.openLink, url));
2237
-
2238
- case 1:
2239
- case "end":
2240
- return _context4.stop();
2241
- }
2242
- }
2243
- }, _callee4);
2244
- }));
2245
-
2246
- return function openLink(_x) {
2247
- return _ref4.apply(this, arguments);
2248
- };
2249
- }();
1434
+ var openLink$1 = function openLink(url) {
1435
+ return new Promise(function ($return, $error) {
1436
+ return $return(sendMessage(commands.openLink, url));
1437
+ });
1438
+ };
2250
1439
  /**
2251
1440
  * Open a link explicitly in the external browser.
2252
1441
  *
@@ -2255,32 +1444,13 @@
2255
1444
  * @return {Promise<any>}
2256
1445
  */
2257
1446
 
2258
- var openLinkExternal =
2259
- /*#__PURE__*/
2260
- function () {
2261
- var _ref5 = _asyncToGenerator(
2262
- /*#__PURE__*/
2263
- regenerator.mark(function _callee5(url) {
2264
- return regenerator.wrap(function _callee5$(_context5) {
2265
- while (1) {
2266
- switch (_context5.prev = _context5.next) {
2267
- case 0:
2268
- return _context5.abrupt("return", sendMessage$4(commands.openLink, url, {
2269
- inAppBrowser: false
2270
- }));
2271
-
2272
- case 1:
2273
- case "end":
2274
- return _context5.stop();
2275
- }
2276
- }
2277
- }, _callee5);
2278
- }));
2279
-
2280
- return function openLinkExternal(_x2) {
2281
- return _ref5.apply(this, arguments);
2282
- };
2283
- }();
1447
+ var openLinkExternal$1 = function openLinkExternal(url) {
1448
+ return new Promise(function ($return, $error) {
1449
+ return $return(sendMessage(commands.openLink, url, {
1450
+ inAppBrowser: false
1451
+ }));
1452
+ });
1453
+ };
2284
1454
  /**
2285
1455
  * Open a link explicitly in the internal browser.
2286
1456
  *
@@ -2289,32 +1459,13 @@
2289
1459
  * @return {Promise<any>}
2290
1460
  */
2291
1461
 
2292
- var openLinkInternal =
2293
- /*#__PURE__*/
2294
- function () {
2295
- var _ref6 = _asyncToGenerator(
2296
- /*#__PURE__*/
2297
- regenerator.mark(function _callee6(url) {
2298
- return regenerator.wrap(function _callee6$(_context6) {
2299
- while (1) {
2300
- switch (_context6.prev = _context6.next) {
2301
- case 0:
2302
- return _context6.abrupt("return", sendMessage$4(commands.openLink, url, {
2303
- inAppBrowser: true
2304
- }));
2305
-
2306
- case 1:
2307
- case "end":
2308
- return _context6.stop();
2309
- }
2310
- }
2311
- }, _callee6);
2312
- }));
2313
-
2314
- return function openLinkInternal(_x3) {
2315
- return _ref6.apply(this, arguments);
2316
- };
2317
- }();
1462
+ var openLinkInternal$1 = function openLinkInternal(url) {
1463
+ return new Promise(function ($return, $error) {
1464
+ return $return(sendMessage(commands.openLink, url, {
1465
+ inAppBrowser: true
1466
+ }));
1467
+ });
1468
+ };
2318
1469
  /**
2319
1470
  * Open a native file upload dialog on device which do not support it by default.
2320
1471
  *
@@ -2323,30 +1474,11 @@
2323
1474
  * @return {Promise<any>}
2324
1475
  */
2325
1476
 
2326
- var openNativeFileDialog =
2327
- /*#__PURE__*/
2328
- function () {
2329
- var _ref7 = _asyncToGenerator(
2330
- /*#__PURE__*/
2331
- regenerator.mark(function _callee7() {
2332
- return regenerator.wrap(function _callee7$(_context7) {
2333
- while (1) {
2334
- switch (_context7.prev = _context7.next) {
2335
- case 0:
2336
- return _context7.abrupt("return", sendMessage$4(commands.nativeUpload));
2337
-
2338
- case 1:
2339
- case "end":
2340
- return _context7.stop();
2341
- }
2342
- }
2343
- }, _callee7);
2344
- }));
2345
-
2346
- return function openNativeFileDialog() {
2347
- return _ref7.apply(this, arguments);
2348
- };
2349
- }();
1477
+ var openNativeFileDialog = function openNativeFileDialog() {
1478
+ return new Promise(function ($return, $error) {
1479
+ return $return(sendMessage(commands.nativeUpload));
1480
+ });
1481
+ };
2350
1482
  /**
2351
1483
  * Open a share dialog on native devices
2352
1484
  *
@@ -2363,126 +1495,50 @@
2363
1495
  * @return {Promise<string>}
2364
1496
  */
2365
1497
 
2366
- var openNativeShareDialog =
2367
- /*#__PURE__*/
2368
- function () {
2369
- var _ref8 = _asyncToGenerator(
2370
- /*#__PURE__*/
2371
- regenerator.mark(function _callee8(content) {
2372
- return regenerator.wrap(function _callee8$(_context8) {
2373
- while (1) {
2374
- switch (_context8.prev = _context8.next) {
2375
- case 0:
2376
- return _context8.abrupt("return", sendMessage$4(commands.nativeShare, content));
2377
-
2378
- case 1:
2379
- case "end":
2380
- return _context8.stop();
2381
- }
2382
- }
2383
- }, _callee8);
2384
- }));
2385
-
2386
- return function openNativeShareDialog(_x4) {
2387
- return _ref8.apply(this, arguments);
2388
- };
2389
- }();
1498
+ var openNativeShareDialog$1 = function openNativeShareDialog(content) {
1499
+ return new Promise(function ($return, $error) {
1500
+ return $return(sendMessage(commands.nativeShare, content));
1501
+ });
1502
+ };
2390
1503
  /**
2391
1504
  * Get the content languages configured for the branch.
2392
1505
  *
2393
1506
  * @return {Promise<Object>}
2394
1507
  */
2395
1508
 
2396
- var getBranchLanguages =
2397
- /*#__PURE__*/
2398
- function () {
2399
- var _ref9 = _asyncToGenerator(
2400
- /*#__PURE__*/
2401
- regenerator.mark(function _callee9() {
2402
- return regenerator.wrap(function _callee9$(_context9) {
2403
- while (1) {
2404
- switch (_context9.prev = _context9.next) {
2405
- case 0:
2406
- return _context9.abrupt("return", sendMessage$4(commands.langInfos).then(function (res) {
2407
- return res.branchLanguages;
2408
- }));
2409
-
2410
- case 1:
2411
- case "end":
2412
- return _context9.stop();
2413
- }
2414
- }
2415
- }, _callee9);
2416
- }));
2417
-
2418
- return function getBranchLanguages() {
2419
- return _ref9.apply(this, arguments);
2420
- };
2421
- }();
1509
+ var getBranchLanguages$1 = function getBranchLanguages() {
1510
+ return new Promise(function ($return, $error) {
1511
+ return $return(sendMessage(commands.langInfos).then(function (res) {
1512
+ return res.branchLanguages;
1513
+ }));
1514
+ });
1515
+ };
2422
1516
  /**
2423
1517
  * Get the default content language configured for the branch.
2424
1518
  *
2425
1519
  * @return {Promise<Object>}
2426
1520
  */
2427
1521
 
2428
- var getBranchDefaultLanguage$1 =
2429
- /*#__PURE__*/
2430
- function () {
2431
- var _ref10 = _asyncToGenerator(
2432
- /*#__PURE__*/
2433
- regenerator.mark(function _callee10() {
2434
- return regenerator.wrap(function _callee10$(_context10) {
2435
- while (1) {
2436
- switch (_context10.prev = _context10.next) {
2437
- case 0:
2438
- return _context10.abrupt("return", sendMessage$4(commands.langInfos).then(function (res) {
2439
- return res.branchDefaultLanguage;
2440
- }));
2441
-
2442
- case 1:
2443
- case "end":
2444
- return _context10.stop();
2445
- }
2446
- }
2447
- }, _callee10);
2448
- }));
2449
-
2450
- return function getBranchDefaultLanguage() {
2451
- return _ref10.apply(this, arguments);
2452
- };
2453
- }();
1522
+ var getBranchDefaultLanguage$1 = function getBranchDefaultLanguage() {
1523
+ return new Promise(function ($return, $error) {
1524
+ return $return(sendMessage(commands.langInfos).then(function (res) {
1525
+ return res.branchDefaultLanguage;
1526
+ }));
1527
+ });
1528
+ };
2454
1529
  /**
2455
1530
  * Get all content languages supported by the Staffbase app.
2456
1531
  *
2457
1532
  * @return {Promise<Object>}
2458
1533
  */
2459
1534
 
2460
- var getContentLanguages =
2461
- /*#__PURE__*/
2462
- function () {
2463
- var _ref11 = _asyncToGenerator(
2464
- /*#__PURE__*/
2465
- regenerator.mark(function _callee11() {
2466
- return regenerator.wrap(function _callee11$(_context11) {
2467
- while (1) {
2468
- switch (_context11.prev = _context11.next) {
2469
- case 0:
2470
- return _context11.abrupt("return", sendMessage$4(commands.langInfos).then(function (res) {
2471
- return res.contentLanguages;
2472
- }));
2473
-
2474
- case 1:
2475
- case "end":
2476
- return _context11.stop();
2477
- }
2478
- }
2479
- }, _callee11);
2480
- }));
2481
-
2482
- return function getContentLanguages() {
2483
- return _ref11.apply(this, arguments);
2484
- };
2485
- }();
1535
+ var getContentLanguages$1 = function getContentLanguages() {
1536
+ return new Promise(function ($return, $error) {
1537
+ return $return(sendMessage(commands.langInfos).then(function (res) {
1538
+ return res.contentLanguages;
1539
+ }));
1540
+ });
1541
+ };
2486
1542
  /**
2487
1543
  * Gets the chosen language from a given content object
2488
1544
  *
@@ -2495,141 +1551,123 @@
2495
1551
  * @return {Promise<string>}
2496
1552
  */
2497
1553
 
2498
- var getPreferredContentLocale$1 =
2499
- /*#__PURE__*/
2500
- function () {
2501
- var _ref12 = _asyncToGenerator(
2502
- /*#__PURE__*/
2503
- regenerator.mark(function _callee12(content) {
2504
- return regenerator.wrap(function _callee12$(_context12) {
2505
- while (1) {
2506
- switch (_context12.prev = _context12.next) {
2507
- case 0:
2508
- return _context12.abrupt("return", sendMessage$4(commands.prefContentLang, content));
2509
-
2510
- case 1:
2511
- case "end":
2512
- return _context12.stop();
2513
- }
2514
- }
2515
- }, _callee12);
2516
- }));
1554
+ var getPreferredContentLocale$1 = function getPreferredContentLocale(content) {
1555
+ return new Promise(function ($return, $error) {
1556
+ return $return(sendMessage(commands.prefContentLang, content));
1557
+ });
1558
+ };
2517
1559
 
2518
- return function getPreferredContentLocale(_x5) {
2519
- return _ref12.apply(this, arguments);
2520
- };
2521
- }();
2522
-
2523
- var compareVersions = createCommonjsModule(function (module, exports) {
2524
- /* global define */
2525
- (function (root, factory) {
2526
- /* istanbul ignore next */
2527
- {
2528
- module.exports = factory();
2529
- }
2530
- }(commonjsGlobal, function () {
1560
+ function compareVersions(v1, v2) {
1561
+ // validate input and split into segments
1562
+ const n1 = validateAndParse(v1);
1563
+ const n2 = validateAndParse(v2); // pop off the patch
2531
1564
 
2532
- var semver = /^v?(?:\d+)(\.(?:[x*]|\d+)(\.(?:[x*]|\d+)(\.(?:[x*]|\d+))?(?:-[\da-z\-]+(?:\.[\da-z\-]+)*)?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i;
1565
+ const p1 = n1.pop();
1566
+ const p2 = n2.pop(); // validate numbers
2533
1567
 
2534
- function indexOrEnd(str, q) {
2535
- return str.indexOf(q) === -1 ? str.length : str.indexOf(q);
1568
+ const r = compareSegments(n1, n2);
1569
+ if (r !== 0) return r; // validate pre-release
1570
+
1571
+ if (p1 && p2) {
1572
+ return compareSegments(p1.split('.'), p2.split('.'));
1573
+ } else if (p1 || p2) {
1574
+ return p1 ? -1 : 1;
2536
1575
  }
2537
1576
 
2538
- function split(v) {
2539
- var c = v.replace(/^v/, '').replace(/\+.*$/, '');
2540
- var patchIndex = indexOrEnd(c, '-');
2541
- var arr = c.substring(0, patchIndex).split('.');
2542
- arr.push(c.substring(patchIndex + 1));
2543
- return arr;
1577
+ 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
+ };
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;
2544
1601
  }
2545
1602
 
2546
- function tryParse(v) {
2547
- return isNaN(Number(v)) ? v : Number(v);
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
+ const semver = /^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i;
1611
+
1612
+ const validateAndParse = v => {
1613
+ if (typeof v !== 'string') {
1614
+ throw new TypeError('Invalid argument expected string');
2548
1615
  }
2549
1616
 
2550
- function validate(version) {
2551
- if (typeof version !== 'string') {
2552
- throw new TypeError('Invalid argument expected string');
2553
- }
2554
- if (!semver.test(version)) {
2555
- throw new Error('Invalid argument not valid semver (\''+version+'\' received)');
2556
- }
1617
+ const match = v.match(semver);
1618
+
1619
+ if (!match) {
1620
+ throw new Error(`Invalid argument not valid semver ('${v}' received)`);
2557
1621
  }
2558
1622
 
2559
- function compareVersions(v1, v2) {
2560
- [v1, v2].forEach(validate);
1623
+ match.shift();
1624
+ return match;
1625
+ };
2561
1626
 
2562
- var s1 = split(v1);
2563
- var s2 = split(v2);
1627
+ const isWildcard = s => s === '*' || s === 'x' || s === 'X';
2564
1628
 
2565
- for (var i = 0; i < Math.max(s1.length - 1, s2.length - 1); i++) {
2566
- var n1 = parseInt(s1[i] || 0, 10);
2567
- var n2 = parseInt(s2[i] || 0, 10);
1629
+ const tryParse = v => {
1630
+ const n = parseInt(v, 10);
1631
+ return isNaN(n) ? v : n;
1632
+ };
2568
1633
 
2569
- if (n1 > n2) return 1;
2570
- if (n2 > n1) return -1;
2571
- }
1634
+ const forceType = (a, b) => typeof a !== typeof b ? [String(a), String(b)] : [a, b];
2572
1635
 
2573
- var sp1 = s1[s1.length - 1];
2574
- var sp2 = s2[s2.length - 1];
1636
+ const compareStrings = (a, b) => {
1637
+ if (isWildcard(a) || isWildcard(b)) return 0;
1638
+ const [ap, bp] = forceType(tryParse(a), tryParse(b));
1639
+ if (ap > bp) return 1;
1640
+ if (ap < bp) return -1;
1641
+ return 0;
1642
+ };
2575
1643
 
2576
- if (sp1 && sp2) {
2577
- var p1 = sp1.split('.').map(tryParse);
2578
- var p2 = sp2.split('.').map(tryParse);
1644
+ const compareSegments = (a, b) => {
1645
+ for (let i = 0; i < Math.max(a.length, b.length); i++) {
1646
+ const r = compareStrings(a[i] || 0, b[i] || 0);
1647
+ if (r !== 0) return r;
1648
+ }
2579
1649
 
2580
- for (i = 0; i < Math.max(p1.length, p2.length); i++) {
2581
- if (p1[i] === undefined || typeof p2[i] === 'string' && typeof p1[i] === 'number') return -1;
2582
- if (p2[i] === undefined || typeof p1[i] === 'string' && typeof p2[i] === 'number') return 1;
1650
+ return 0;
1651
+ };
2583
1652
 
2584
- if (p1[i] > p2[i]) return 1;
2585
- if (p2[i] > p1[i]) return -1;
2586
- }
2587
- } else if (sp1 || sp2) {
2588
- return sp1 ? -1 : 1;
2589
- }
1653
+ const operatorResMap = {
1654
+ '>': [1],
1655
+ '>=': [0, 1],
1656
+ '=': [0],
1657
+ '<=': [-1, 0],
1658
+ '<': [-1]
1659
+ };
1660
+ const allowedOperators = Object.keys(operatorResMap);
2590
1661
 
2591
- return 0;
2592
- }
2593
- var allowedOperators = [
2594
- '>',
2595
- '>=',
2596
- '=',
2597
- '<',
2598
- '<='
2599
- ];
2600
-
2601
- function validateOperator(op) {
2602
- if (typeof op !== 'string') {
2603
- throw new TypeError('Invalid operator type, expected string but got ' + typeof op);
2604
- }
2605
- if (allowedOperators.indexOf(op) === -1) {
2606
- throw new TypeError('Invalid operator, expected one of ' + allowedOperators.join('|'));
2607
- }
1662
+ const assertValidOperator = op => {
1663
+ if (typeof op !== 'string') {
1664
+ throw new TypeError(`Invalid operator type, expected string but got ${typeof op}`);
2608
1665
  }
2609
1666
 
2610
- compareVersions.compare = function (v1, v2, operator) {
2611
- // Validate operator
2612
- validateOperator(operator);
2613
-
2614
- // TODO: there might be a better way instead of doing this
2615
- switch(operator) {
2616
- case '>':
2617
- return compareVersions(v1, v2) > 0;
2618
- case '>=':
2619
- return compareVersions(v1, v2) >= 0;
2620
- case '<':
2621
- return compareVersions(v1, v2) < 0;
2622
- case '<=':
2623
- return compareVersions(v1, v2) <= 0;
2624
- default:
2625
- // Since validateOperator already checks the operator, this case in the switch checks for the '=' operator
2626
- return compareVersions(v1, v2) === 0;
2627
- }
2628
- };
2629
-
2630
- return compareVersions;
2631
- }));
2632
- });
1667
+ if (allowedOperators.indexOf(op) === -1) {
1668
+ throw new Error(`Invalid operator, expected one of ${allowedOperators.join('|')}`);
1669
+ }
1670
+ };
2633
1671
 
2634
1672
  /**
2635
1673
  * Check if device is using ios.
@@ -2637,288 +1675,117 @@
2637
1675
  * @return {Promise<boolean>}
2638
1676
  */
2639
1677
 
2640
- var isIos$1 =
2641
- /*#__PURE__*/
2642
- function () {
2643
- var _ref = _asyncToGenerator(
2644
- /*#__PURE__*/
2645
- regenerator.mark(function _callee() {
2646
- return regenerator.wrap(function _callee$(_context) {
2647
- while (1) {
2648
- switch (_context.prev = _context.next) {
2649
- case 0:
2650
- return _context.abrupt("return", sendMessage$4(commands.ios));
2651
-
2652
- case 1:
2653
- case "end":
2654
- return _context.stop();
2655
- }
2656
- }
2657
- }, _callee);
2658
- }));
2659
-
2660
- return function isIos() {
2661
- return _ref.apply(this, arguments);
2662
- };
2663
- }();
1678
+ var isIos = function isIos() {
1679
+ return new Promise(function ($return, $error) {
1680
+ return $return(sendMessage(commands.ios));
1681
+ });
1682
+ };
2664
1683
  /**
2665
1684
  * Check if device is using android.
2666
1685
  *
2667
1686
  * @return {Promise<boolean>}
2668
1687
  */
2669
1688
 
2670
- var isAndroid$1 =
2671
- /*#__PURE__*/
2672
- function () {
2673
- var _ref2 = _asyncToGenerator(
2674
- /*#__PURE__*/
2675
- regenerator.mark(function _callee2() {
2676
- return regenerator.wrap(function _callee2$(_context2) {
2677
- while (1) {
2678
- switch (_context2.prev = _context2.next) {
2679
- case 0:
2680
- return _context2.abrupt("return", sendMessage$4(commands.android));
2681
-
2682
- case 1:
2683
- case "end":
2684
- return _context2.stop();
2685
- }
2686
- }
2687
- }, _callee2);
2688
- }));
2689
-
2690
- return function isAndroid() {
2691
- return _ref2.apply(this, arguments);
2692
- };
2693
- }();
1689
+ var isAndroid = function isAndroid() {
1690
+ return new Promise(function ($return, $error) {
1691
+ return $return(sendMessage(commands.android));
1692
+ });
1693
+ };
2694
1694
  /**
2695
1695
  * Check if device is able to perform a download.
2696
1696
  *
2697
1697
  * @return {Promise<boolean>}
2698
1698
  */
2699
1699
 
2700
- var canDownload =
2701
- /*#__PURE__*/
2702
- function () {
2703
- var _ref3 = _asyncToGenerator(
2704
- /*#__PURE__*/
2705
- regenerator.mark(function _callee3() {
2706
- var _ref4, _ref5, native, version, ios, dashIndex;
2707
-
2708
- return regenerator.wrap(function _callee3$(_context3) {
2709
- while (1) {
2710
- switch (_context3.prev = _context3.next) {
2711
- case 0:
2712
- _context3.next = 2;
2713
- return Promise.all([isNative$1(), getVersion$1(), isIos$1()]);
2714
-
2715
- case 2:
2716
- _ref4 = _context3.sent;
2717
- _ref5 = _slicedToArray(_ref4, 3);
2718
- native = _ref5[0];
2719
- version = _ref5[1];
2720
- ios = _ref5[2];
2721
- // support any development versions like X.Y-dev for compare versions
2722
- dashIndex = version.indexOf('-');
2723
- version = version.substring(0, dashIndex != -1 ? dashIndex : version.length); // mobile ios devices can not download with an app version less than 3.5
2724
- // but apps below 3.5 don't have the platform information from the frontend available
2725
- // so we disable download for all native ios devices under these conditions
2726
-
2727
- return _context3.abrupt("return", !(compareVersions(version, '3.5') < 0 && native && ios));
2728
-
2729
- case 10:
2730
- case "end":
2731
- return _context3.stop();
2732
- }
2733
- }
2734
- }, _callee3);
2735
- }));
1700
+ var canDownload = function canDownload() {
1701
+ return new Promise(function ($return, $error) {
1702
+ var _await$Promise$all, _await$Promise$all2, native, version, ios, dashIndex;
2736
1703
 
2737
- return function canDownload() {
2738
- return _ref3.apply(this, arguments);
2739
- };
2740
- }();
1704
+ return Promise.resolve(Promise.all([isNative(), getVersion(), isIos()])).then(function ($await_1) {
1705
+ try {
1706
+ _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];
1707
+ dashIndex = version.indexOf('-');
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
+ });
1718
+ };
2741
1719
 
1720
+ /**
1721
+ * Interface exports
1722
+ */
2742
1723
  /**
2743
1724
  * Check if device is able to perform a download.
2744
1725
  * @function
2745
1726
  * @return {Promise<boolean>}
2746
1727
  */
2747
1728
 
2748
- var deviceCanDownload =
2749
- /*#__PURE__*/
2750
- function () {
2751
- var _ref = _asyncToGenerator(
2752
- /*#__PURE__*/
2753
- regenerator.mark(function _callee() {
2754
- return regenerator.wrap(function _callee$(_context) {
2755
- while (1) {
2756
- switch (_context.prev = _context.next) {
2757
- case 0:
2758
- return _context.abrupt("return", canDownload());
2759
-
2760
- case 1:
2761
- case "end":
2762
- return _context.stop();
2763
- }
2764
- }
2765
- }, _callee);
2766
- }));
2767
-
2768
- return function deviceCanDownload() {
2769
- return _ref.apply(this, arguments);
2770
- };
2771
- }();
1729
+ var deviceCanDownload = function deviceCanDownload() {
1730
+ return new Promise(function ($return, $error) {
1731
+ return $return(canDownload());
1732
+ });
1733
+ };
2772
1734
  /**
2773
1735
  * Check if device is using ios.
2774
1736
  * @function
2775
1737
  * @return {Promise<boolean>}
2776
1738
  */
2777
1739
 
2778
- var isIosDevice =
2779
- /*#__PURE__*/
2780
- function () {
2781
- var _ref2 = _asyncToGenerator(
2782
- /*#__PURE__*/
2783
- regenerator.mark(function _callee2() {
2784
- return regenerator.wrap(function _callee2$(_context2) {
2785
- while (1) {
2786
- switch (_context2.prev = _context2.next) {
2787
- case 0:
2788
- return _context2.abrupt("return", isIos$1());
2789
-
2790
- case 1:
2791
- case "end":
2792
- return _context2.stop();
2793
- }
2794
- }
2795
- }, _callee2);
2796
- }));
2797
-
2798
- return function isIosDevice() {
2799
- return _ref2.apply(this, arguments);
2800
- };
2801
- }();
1740
+ var isIosDevice = function isIosDevice() {
1741
+ return new Promise(function ($return, $error) {
1742
+ return $return(isIos());
1743
+ });
1744
+ };
2802
1745
  /**
2803
1746
  * Check if device is using android.
2804
1747
  * @function
2805
1748
  * @return {Promise<boolean>}
2806
1749
  */
2807
1750
 
2808
- var isAndroidDevice =
2809
- /*#__PURE__*/
2810
- function () {
2811
- var _ref3 = _asyncToGenerator(
2812
- /*#__PURE__*/
2813
- regenerator.mark(function _callee3() {
2814
- return regenerator.wrap(function _callee3$(_context3) {
2815
- while (1) {
2816
- switch (_context3.prev = _context3.next) {
2817
- case 0:
2818
- return _context3.abrupt("return", isAndroid$1());
2819
-
2820
- case 1:
2821
- case "end":
2822
- return _context3.stop();
2823
- }
2824
- }
2825
- }, _callee3);
2826
- }));
2827
-
2828
- return function isAndroidDevice() {
2829
- return _ref3.apply(this, arguments);
2830
- };
2831
- }();
1751
+ var isAndroidDevice = function isAndroidDevice() {
1752
+ return new Promise(function ($return, $error) {
1753
+ return $return(isAndroid());
1754
+ });
1755
+ };
2832
1756
  /**
2833
1757
  * Get the version of the Staffbase App.
2834
1758
  * @function
2835
1759
  * @return {Promise<string>}
2836
1760
  */
2837
1761
 
2838
- var getAppVersion =
2839
- /*#__PURE__*/
2840
- function () {
2841
- var _ref4 = _asyncToGenerator(
2842
- /*#__PURE__*/
2843
- regenerator.mark(function _callee4() {
2844
- return regenerator.wrap(function _callee4$(_context4) {
2845
- while (1) {
2846
- switch (_context4.prev = _context4.next) {
2847
- case 0:
2848
- return _context4.abrupt("return", getVersion$1());
2849
-
2850
- case 1:
2851
- case "end":
2852
- return _context4.stop();
2853
- }
2854
- }
2855
- }, _callee4);
2856
- }));
2857
-
2858
- return function getAppVersion() {
2859
- return _ref4.apply(this, arguments);
2860
- };
2861
- }();
1762
+ var getAppVersion = function getAppVersion() {
1763
+ return new Promise(function ($return, $error) {
1764
+ return $return(getVersion());
1765
+ });
1766
+ };
2862
1767
  /**
2863
1768
  * Check if app is native.
2864
1769
  * @function
2865
1770
  * @return {Promise<boolean>}
2866
1771
  */
2867
1772
 
2868
- var isNativeApp =
2869
- /*#__PURE__*/
2870
- function () {
2871
- var _ref5 = _asyncToGenerator(
2872
- /*#__PURE__*/
2873
- regenerator.mark(function _callee5() {
2874
- return regenerator.wrap(function _callee5$(_context5) {
2875
- while (1) {
2876
- switch (_context5.prev = _context5.next) {
2877
- case 0:
2878
- return _context5.abrupt("return", isNative$1());
2879
-
2880
- case 1:
2881
- case "end":
2882
- return _context5.stop();
2883
- }
2884
- }
2885
- }, _callee5);
2886
- }));
2887
-
2888
- return function isNativeApp() {
2889
- return _ref5.apply(this, arguments);
2890
- };
2891
- }();
1773
+ var isNativeApp = function isNativeApp() {
1774
+ return new Promise(function ($return, $error) {
1775
+ return $return(isNative());
1776
+ });
1777
+ };
2892
1778
  /**
2893
1779
  * Check if app is mobile.
2894
1780
  * @function
2895
1781
  * @return {Promise<boolean>}
2896
1782
  */
2897
1783
 
2898
- var isMobileApp =
2899
- /*#__PURE__*/
2900
- function () {
2901
- var _ref6 = _asyncToGenerator(
2902
- /*#__PURE__*/
2903
- regenerator.mark(function _callee6() {
2904
- return regenerator.wrap(function _callee6$(_context6) {
2905
- while (1) {
2906
- switch (_context6.prev = _context6.next) {
2907
- case 0:
2908
- return _context6.abrupt("return", isMobile$1());
2909
-
2910
- case 1:
2911
- case "end":
2912
- return _context6.stop();
2913
- }
2914
- }
2915
- }, _callee6);
2916
- }));
2917
-
2918
- return function isMobileApp() {
2919
- return _ref6.apply(this, arguments);
2920
- };
2921
- }();
1784
+ var isMobileApp = function isMobileApp() {
1785
+ return new Promise(function ($return, $error) {
1786
+ return $return(isMobile());
1787
+ });
1788
+ };
2922
1789
  /**
2923
1790
  * Open a link through the app.
2924
1791
  *
@@ -2930,30 +1797,11 @@
2930
1797
  * @return {Promise<any>}
2931
1798
  */
2932
1799
 
2933
- var openLink$2 =
2934
- /*#__PURE__*/
2935
- function () {
2936
- var _ref7 = _asyncToGenerator(
2937
- /*#__PURE__*/
2938
- regenerator.mark(function _callee7(url) {
2939
- return regenerator.wrap(function _callee7$(_context7) {
2940
- while (1) {
2941
- switch (_context7.prev = _context7.next) {
2942
- case 0:
2943
- return _context7.abrupt("return", openLink$1(url));
2944
-
2945
- case 1:
2946
- case "end":
2947
- return _context7.stop();
2948
- }
2949
- }
2950
- }, _callee7);
2951
- }));
2952
-
2953
- return function openLink(_x) {
2954
- return _ref7.apply(this, arguments);
2955
- };
2956
- }();
1800
+ var openLink = function openLink(url) {
1801
+ return new Promise(function ($return, $error) {
1802
+ return $return(openLink$1(url));
1803
+ });
1804
+ };
2957
1805
  /**
2958
1806
  * Open a link explicitly in the external browser.
2959
1807
  *
@@ -2962,30 +1810,11 @@
2962
1810
  * @return {Promise<any>}
2963
1811
  */
2964
1812
 
2965
- var openLinkExternal$1 =
2966
- /*#__PURE__*/
2967
- function () {
2968
- var _ref8 = _asyncToGenerator(
2969
- /*#__PURE__*/
2970
- regenerator.mark(function _callee8(url) {
2971
- return regenerator.wrap(function _callee8$(_context8) {
2972
- while (1) {
2973
- switch (_context8.prev = _context8.next) {
2974
- case 0:
2975
- return _context8.abrupt("return", openLinkExternal(url));
2976
-
2977
- case 1:
2978
- case "end":
2979
- return _context8.stop();
2980
- }
2981
- }
2982
- }, _callee8);
2983
- }));
2984
-
2985
- return function openLinkExternal(_x2) {
2986
- return _ref8.apply(this, arguments);
2987
- };
2988
- }();
1813
+ var openLinkExternal = function openLinkExternal(url) {
1814
+ return new Promise(function ($return, $error) {
1815
+ return $return(openLinkExternal$1(url));
1816
+ });
1817
+ };
2989
1818
  /**
2990
1819
  * Open a link explicitly in the internal browser.
2991
1820
  *
@@ -2994,120 +1823,44 @@
2994
1823
  * @return {Promise<any>}
2995
1824
  */
2996
1825
 
2997
- var openLinkInternal$1 =
2998
- /*#__PURE__*/
2999
- function () {
3000
- var _ref9 = _asyncToGenerator(
3001
- /*#__PURE__*/
3002
- regenerator.mark(function _callee9(url) {
3003
- return regenerator.wrap(function _callee9$(_context9) {
3004
- while (1) {
3005
- switch (_context9.prev = _context9.next) {
3006
- case 0:
3007
- return _context9.abrupt("return", openLinkInternal(url));
3008
-
3009
- case 1:
3010
- case "end":
3011
- return _context9.stop();
3012
- }
3013
- }
3014
- }, _callee9);
3015
- }));
3016
-
3017
- return function openLinkInternal(_x3) {
3018
- return _ref9.apply(this, arguments);
3019
- };
3020
- }();
1826
+ var openLinkInternal = function openLinkInternal(url) {
1827
+ return new Promise(function ($return, $error) {
1828
+ return $return(openLinkInternal$1(url));
1829
+ });
1830
+ };
3021
1831
  /**
3022
1832
  * Get all enabled content languages configured in the app.
3023
1833
  * @function
3024
1834
  * @return {Promise<any>}
3025
1835
  */
3026
1836
 
3027
- var getBranchLanguages$1 =
3028
- /*#__PURE__*/
3029
- function () {
3030
- var _ref10 = _asyncToGenerator(
3031
- /*#__PURE__*/
3032
- regenerator.mark(function _callee10() {
3033
- return regenerator.wrap(function _callee10$(_context10) {
3034
- while (1) {
3035
- switch (_context10.prev = _context10.next) {
3036
- case 0:
3037
- return _context10.abrupt("return", getBranchLanguages());
3038
-
3039
- case 1:
3040
- case "end":
3041
- return _context10.stop();
3042
- }
3043
- }
3044
- }, _callee10);
3045
- }));
3046
-
3047
- return function getBranchLanguages() {
3048
- return _ref10.apply(this, arguments);
3049
- };
3050
- }();
1837
+ var getBranchLanguages = function getBranchLanguages() {
1838
+ return new Promise(function ($return, $error) {
1839
+ return $return(getBranchLanguages$1());
1840
+ });
1841
+ };
3051
1842
  /**
3052
1843
  * Get the default content language configured in the app.
3053
1844
  * @function
3054
1845
  * @return {Promise<any>}
3055
1846
  */
3056
1847
 
3057
- var getBranchDefaultLanguage$2 =
3058
- /*#__PURE__*/
3059
- function () {
3060
- var _ref11 = _asyncToGenerator(
3061
- /*#__PURE__*/
3062
- regenerator.mark(function _callee11() {
3063
- return regenerator.wrap(function _callee11$(_context11) {
3064
- while (1) {
3065
- switch (_context11.prev = _context11.next) {
3066
- case 0:
3067
- return _context11.abrupt("return", getBranchDefaultLanguage$1());
3068
-
3069
- case 1:
3070
- case "end":
3071
- return _context11.stop();
3072
- }
3073
- }
3074
- }, _callee11);
3075
- }));
3076
-
3077
- return function getBranchDefaultLanguage() {
3078
- return _ref11.apply(this, arguments);
3079
- };
3080
- }();
1848
+ var getBranchDefaultLanguage = function getBranchDefaultLanguage() {
1849
+ return new Promise(function ($return, $error) {
1850
+ return $return(getBranchDefaultLanguage$1());
1851
+ });
1852
+ };
3081
1853
  /**
3082
1854
  * Get all content languages supported by the app.
3083
1855
  * @function
3084
1856
  * @return {Promise<any>}
3085
1857
  */
3086
1858
 
3087
- var getContentLanguages$1 =
3088
- /*#__PURE__*/
3089
- function () {
3090
- var _ref12 = _asyncToGenerator(
3091
- /*#__PURE__*/
3092
- regenerator.mark(function _callee12() {
3093
- return regenerator.wrap(function _callee12$(_context12) {
3094
- while (1) {
3095
- switch (_context12.prev = _context12.next) {
3096
- case 0:
3097
- return _context12.abrupt("return", getContentLanguages());
3098
-
3099
- case 1:
3100
- case "end":
3101
- return _context12.stop();
3102
- }
3103
- }
3104
- }, _callee12);
3105
- }));
3106
-
3107
- return function getContentLanguages() {
3108
- return _ref12.apply(this, arguments);
3109
- };
3110
- }();
1859
+ var getContentLanguages = function getContentLanguages() {
1860
+ return new Promise(function ($return, $error) {
1861
+ return $return(getContentLanguages$1());
1862
+ });
1863
+ };
3111
1864
  /**
3112
1865
  * Gets the chosen language from a given content object
3113
1866
  *
@@ -3120,30 +1873,11 @@
3120
1873
  * @return {Promise<string>}
3121
1874
  */
3122
1875
 
3123
- var getPreferredContentLocale$2 =
3124
- /*#__PURE__*/
3125
- function () {
3126
- var _ref13 = _asyncToGenerator(
3127
- /*#__PURE__*/
3128
- regenerator.mark(function _callee13(content) {
3129
- return regenerator.wrap(function _callee13$(_context13) {
3130
- while (1) {
3131
- switch (_context13.prev = _context13.next) {
3132
- case 0:
3133
- return _context13.abrupt("return", getPreferredContentLocale$1(content));
3134
-
3135
- case 1:
3136
- case "end":
3137
- return _context13.stop();
3138
- }
3139
- }
3140
- }, _callee13);
3141
- }));
3142
-
3143
- return function getPreferredContentLocale(_x4) {
3144
- return _ref13.apply(this, arguments);
3145
- };
3146
- }();
1876
+ var getPreferredContentLocale = function getPreferredContentLocale(content) {
1877
+ return new Promise(function ($return, $error) {
1878
+ return $return(getPreferredContentLocale$1(content));
1879
+ });
1880
+ };
3147
1881
  /**
3148
1882
  * Open a share dialog on native devices
3149
1883
  *
@@ -3160,47 +1894,28 @@
3160
1894
  * @return {Promise<string>}
3161
1895
  */
3162
1896
 
3163
- var openNativeShareDialog$1 =
3164
- /*#__PURE__*/
3165
- function () {
3166
- var _ref14 = _asyncToGenerator(
3167
- /*#__PURE__*/
3168
- regenerator.mark(function _callee14(content) {
3169
- return regenerator.wrap(function _callee14$(_context14) {
3170
- while (1) {
3171
- switch (_context14.prev = _context14.next) {
3172
- case 0:
3173
- return _context14.abrupt("return", openNativeShareDialog(content));
3174
-
3175
- case 1:
3176
- case "end":
3177
- return _context14.stop();
3178
- }
3179
- }
3180
- }, _callee14);
3181
- }));
3182
-
3183
- return function openNativeShareDialog(_x5) {
3184
- return _ref14.apply(this, arguments);
3185
- };
3186
- }();
1897
+ var openNativeShareDialog = function openNativeShareDialog(content) {
1898
+ return new Promise(function ($return, $error) {
1899
+ return $return(openNativeShareDialog$1(content));
1900
+ });
1901
+ };
3187
1902
  /* experimental */
3188
1903
 
3189
1904
  exports.deviceCanDownload = deviceCanDownload;
3190
1905
  exports.getAppVersion = getAppVersion;
3191
- exports.getBranchDefaultLanguage = getBranchDefaultLanguage$2;
3192
- exports.getBranchLanguages = getBranchLanguages$1;
3193
- exports.getContentLanguages = getContentLanguages$1;
3194
- exports.getPreferredContentLocale = getPreferredContentLocale$2;
1906
+ exports.getBranchDefaultLanguage = getBranchDefaultLanguage;
1907
+ exports.getBranchLanguages = getBranchLanguages;
1908
+ exports.getContentLanguages = getContentLanguages;
1909
+ exports.getPreferredContentLocale = getPreferredContentLocale;
3195
1910
  exports.isAndroidDevice = isAndroidDevice;
3196
1911
  exports.isIosDevice = isIosDevice;
3197
1912
  exports.isMobileApp = isMobileApp;
3198
1913
  exports.isNativeApp = isNativeApp;
3199
- exports.openLink = openLink$2;
3200
- exports.openLinkExternal = openLinkExternal$1;
3201
- exports.openLinkInternal = openLinkInternal$1;
1914
+ exports.openLink = openLink;
1915
+ exports.openLinkExternal = openLinkExternal;
1916
+ exports.openLinkInternal = openLinkInternal;
3202
1917
  exports.openNativeFileDialog = openNativeFileDialog;
3203
- exports.openNativeShareDialog = openNativeShareDialog$1;
1918
+ exports.openNativeShareDialog = openNativeShareDialog;
3204
1919
 
3205
1920
  Object.defineProperty(exports, '__esModule', { value: true });
3206
1921