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