@staffbase/plugins-client-sdk 2.0.2 → 3.0.0-alpha.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.
- package/dist/plugins-client-sdk.esm.js +128 -43
- package/dist/plugins-client-sdk.esm.js.map +1 -1
- package/dist/plugins-client-sdk.js +128 -42
- package/dist/plugins-client-sdk.js.map +1 -1
- package/dist/plugins-client-sdk.umd.js +128 -42
- package/dist/plugins-client-sdk.umd.js.map +1 -1
- package/dist/plugins-client-sdk.umd.min.js +3 -3
- package/dist/plugins-client-sdk.umd.min.js.map +1 -1
- package/package.json +26 -24
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
* Bundle of @staffbase/plugins-client-sdk
|
|
3
3
|
* @file Staffbase plugins client SDK for JavaScript
|
|
4
4
|
* @see https://github.com/Staffbase/plugins-client-sdk#readme
|
|
5
|
-
* @version
|
|
5
|
+
* @version 3.0.0-alpha.2
|
|
6
6
|
*
|
|
7
7
|
* @author Stefan Staude <stefan.staude@staffbase.com>
|
|
8
8
|
* @author Daniel Große <daniel.grosse@staffbase.com>
|
|
9
9
|
*
|
|
10
|
-
* @copyright
|
|
10
|
+
* @copyright 2026
|
|
11
11
|
* @license Apache-2.0
|
|
12
12
|
*/
|
|
13
13
|
|
|
@@ -40,6 +40,8 @@ var loglevel = {
|
|
|
40
40
|
var undefinedType = "undefined";
|
|
41
41
|
var isIE = typeof window !== undefinedType && typeof window.navigator !== undefinedType && /Trident\/|MSIE /.test(window.navigator.userAgent);
|
|
42
42
|
var logMethods = ["trace", "debug", "info", "warn", "error"];
|
|
43
|
+
var _loggersByName = {};
|
|
44
|
+
var defaultLogger = null;
|
|
43
45
|
|
|
44
46
|
// Cross-browser bind equivalent that works at least back to IE6
|
|
45
47
|
function bindMethod(obj, methodName) {
|
|
@@ -92,23 +94,31 @@ var loglevel = {
|
|
|
92
94
|
|
|
93
95
|
// These private functions always need `this` to be set properly
|
|
94
96
|
|
|
95
|
-
function replaceLoggingMethods(
|
|
97
|
+
function replaceLoggingMethods() {
|
|
96
98
|
/*jshint validthis:true */
|
|
99
|
+
var level = this.getLevel();
|
|
100
|
+
|
|
101
|
+
// Replace the actual methods.
|
|
97
102
|
for (var i = 0; i < logMethods.length; i++) {
|
|
98
103
|
var methodName = logMethods[i];
|
|
99
|
-
this[methodName] = i < level ? noop : this.methodFactory(methodName, level,
|
|
104
|
+
this[methodName] = i < level ? noop : this.methodFactory(methodName, level, this.name);
|
|
100
105
|
}
|
|
101
106
|
|
|
102
107
|
// Define log.log as an alias for log.debug
|
|
103
108
|
this.log = this.debug;
|
|
109
|
+
|
|
110
|
+
// Return any important warnings.
|
|
111
|
+
if (typeof console === undefinedType && level < this.levels.SILENT) {
|
|
112
|
+
return "No console available for logging";
|
|
113
|
+
}
|
|
104
114
|
}
|
|
105
115
|
|
|
106
116
|
// In old IE versions, the console isn't present until you first open it.
|
|
107
117
|
// We build realMethod() replacements here that regenerate logging methods
|
|
108
|
-
function enableLoggingWhenConsoleArrives(methodName
|
|
118
|
+
function enableLoggingWhenConsoleArrives(methodName) {
|
|
109
119
|
return function () {
|
|
110
120
|
if (typeof console !== undefinedType) {
|
|
111
|
-
replaceLoggingMethods.call(this
|
|
121
|
+
replaceLoggingMethods.call(this);
|
|
112
122
|
this[methodName].apply(this, arguments);
|
|
113
123
|
}
|
|
114
124
|
};
|
|
@@ -116,14 +126,34 @@ var loglevel = {
|
|
|
116
126
|
|
|
117
127
|
// By default, we use closely bound real methods wherever possible, and
|
|
118
128
|
// otherwise we wait for a console to appear, and then try again.
|
|
119
|
-
function defaultMethodFactory(methodName,
|
|
129
|
+
function defaultMethodFactory(methodName, _level, _loggerName) {
|
|
120
130
|
/*jshint validthis:true */
|
|
121
131
|
return realMethod(methodName) || enableLoggingWhenConsoleArrives.apply(this, arguments);
|
|
122
132
|
}
|
|
123
|
-
function Logger(name,
|
|
133
|
+
function Logger(name, factory) {
|
|
134
|
+
// Private instance variables.
|
|
124
135
|
var self = this;
|
|
125
|
-
|
|
126
|
-
|
|
136
|
+
/**
|
|
137
|
+
* The level inherited from a parent logger (or a global default). We
|
|
138
|
+
* cache this here rather than delegating to the parent so that it stays
|
|
139
|
+
* in sync with the actual logging methods that we have installed (the
|
|
140
|
+
* parent could change levels but we might not have rebuilt the loggers
|
|
141
|
+
* in this child yet).
|
|
142
|
+
* @type {number}
|
|
143
|
+
*/
|
|
144
|
+
var inheritedLevel;
|
|
145
|
+
/**
|
|
146
|
+
* The default level for this logger, if any. If set, this overrides
|
|
147
|
+
* `inheritedLevel`.
|
|
148
|
+
* @type {number|null}
|
|
149
|
+
*/
|
|
150
|
+
var defaultLevel;
|
|
151
|
+
/**
|
|
152
|
+
* A user-specific level for this logger. If set, this overrides
|
|
153
|
+
* `defaultLevel`.
|
|
154
|
+
* @type {number|null}
|
|
155
|
+
*/
|
|
156
|
+
var userLevel;
|
|
127
157
|
var storageKey = "loglevel";
|
|
128
158
|
if (typeof name === "string") {
|
|
129
159
|
storageKey += ":" + name;
|
|
@@ -156,9 +186,10 @@ var loglevel = {
|
|
|
156
186
|
if (typeof storedLevel === undefinedType) {
|
|
157
187
|
try {
|
|
158
188
|
var cookie = window.document.cookie;
|
|
159
|
-
var
|
|
189
|
+
var cookieName = encodeURIComponent(storageKey);
|
|
190
|
+
var location = cookie.indexOf(cookieName + "=");
|
|
160
191
|
if (location !== -1) {
|
|
161
|
-
storedLevel = /^([^;]+)/.exec(cookie.slice(location))[1];
|
|
192
|
+
storedLevel = /^([^;]+)/.exec(cookie.slice(location + cookieName.length + 1))[1];
|
|
162
193
|
}
|
|
163
194
|
} catch (ignore) {}
|
|
164
195
|
}
|
|
@@ -175,7 +206,6 @@ var loglevel = {
|
|
|
175
206
|
// Use localStorage if available
|
|
176
207
|
try {
|
|
177
208
|
window.localStorage.removeItem(storageKey);
|
|
178
|
-
return;
|
|
179
209
|
} catch (ignore) {}
|
|
180
210
|
|
|
181
211
|
// Use session cookie as fallback
|
|
@@ -183,6 +213,17 @@ var loglevel = {
|
|
|
183
213
|
window.document.cookie = encodeURIComponent(storageKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
|
|
184
214
|
} catch (ignore) {}
|
|
185
215
|
}
|
|
216
|
+
function normalizeLevel(input) {
|
|
217
|
+
var level = input;
|
|
218
|
+
if (typeof level === "string" && self.levels[level.toUpperCase()] !== undefined) {
|
|
219
|
+
level = self.levels[level.toUpperCase()];
|
|
220
|
+
}
|
|
221
|
+
if (typeof level === "number" && level >= 0 && level <= self.levels.SILENT) {
|
|
222
|
+
return level;
|
|
223
|
+
} else {
|
|
224
|
+
throw new TypeError("log.setLevel() called with invalid level: " + input);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
186
227
|
|
|
187
228
|
/*
|
|
188
229
|
*
|
|
@@ -201,35 +242,34 @@ var loglevel = {
|
|
|
201
242
|
};
|
|
202
243
|
self.methodFactory = factory || defaultMethodFactory;
|
|
203
244
|
self.getLevel = function () {
|
|
204
|
-
|
|
245
|
+
if (userLevel != null) {
|
|
246
|
+
return userLevel;
|
|
247
|
+
} else if (defaultLevel != null) {
|
|
248
|
+
return defaultLevel;
|
|
249
|
+
} else {
|
|
250
|
+
return inheritedLevel;
|
|
251
|
+
}
|
|
205
252
|
};
|
|
206
253
|
self.setLevel = function (level, persist) {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
currentLevel = level;
|
|
212
|
-
if (persist !== false) {
|
|
213
|
-
// defaults to true
|
|
214
|
-
persistLevelIfPossible(level);
|
|
215
|
-
}
|
|
216
|
-
replaceLoggingMethods.call(self, level, name);
|
|
217
|
-
if (typeof console === undefinedType && level < self.levels.SILENT) {
|
|
218
|
-
return "No console available for logging";
|
|
219
|
-
}
|
|
220
|
-
} else {
|
|
221
|
-
throw "log.setLevel() called with invalid level: " + level;
|
|
254
|
+
userLevel = normalizeLevel(level);
|
|
255
|
+
if (persist !== false) {
|
|
256
|
+
// defaults to true
|
|
257
|
+
persistLevelIfPossible(userLevel);
|
|
222
258
|
}
|
|
259
|
+
|
|
260
|
+
// NOTE: in v2, this should call rebuild(), which updates children.
|
|
261
|
+
return replaceLoggingMethods.call(self);
|
|
223
262
|
};
|
|
224
263
|
self.setDefaultLevel = function (level) {
|
|
225
|
-
defaultLevel = level;
|
|
264
|
+
defaultLevel = normalizeLevel(level);
|
|
226
265
|
if (!getPersistedLevel()) {
|
|
227
266
|
self.setLevel(level, false);
|
|
228
267
|
}
|
|
229
268
|
};
|
|
230
269
|
self.resetLevel = function () {
|
|
231
|
-
|
|
270
|
+
userLevel = null;
|
|
232
271
|
clearPersistedLevel();
|
|
272
|
+
replaceLoggingMethods.call(self);
|
|
233
273
|
};
|
|
234
274
|
self.enableAll = function (persist) {
|
|
235
275
|
self.setLevel(self.levels.TRACE, persist);
|
|
@@ -237,13 +277,25 @@ var loglevel = {
|
|
|
237
277
|
self.disableAll = function (persist) {
|
|
238
278
|
self.setLevel(self.levels.SILENT, persist);
|
|
239
279
|
};
|
|
280
|
+
self.rebuild = function () {
|
|
281
|
+
if (defaultLogger !== self) {
|
|
282
|
+
inheritedLevel = normalizeLevel(defaultLogger.getLevel());
|
|
283
|
+
}
|
|
284
|
+
replaceLoggingMethods.call(self);
|
|
285
|
+
if (defaultLogger === self) {
|
|
286
|
+
for (var childName in _loggersByName) {
|
|
287
|
+
_loggersByName[childName].rebuild();
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
};
|
|
240
291
|
|
|
241
|
-
// Initialize
|
|
292
|
+
// Initialize all the internal levels.
|
|
293
|
+
inheritedLevel = normalizeLevel(defaultLogger ? defaultLogger.getLevel() : "WARN");
|
|
242
294
|
var initialLevel = getPersistedLevel();
|
|
243
|
-
if (initialLevel
|
|
244
|
-
|
|
295
|
+
if (initialLevel != null) {
|
|
296
|
+
userLevel = normalizeLevel(initialLevel);
|
|
245
297
|
}
|
|
246
|
-
|
|
298
|
+
replaceLoggingMethods.call(self);
|
|
247
299
|
}
|
|
248
300
|
|
|
249
301
|
/*
|
|
@@ -252,15 +304,14 @@ var loglevel = {
|
|
|
252
304
|
*
|
|
253
305
|
*/
|
|
254
306
|
|
|
255
|
-
|
|
256
|
-
var _loggersByName = {};
|
|
307
|
+
defaultLogger = new Logger();
|
|
257
308
|
defaultLogger.getLogger = function getLogger(name) {
|
|
258
309
|
if (typeof name !== "symbol" && typeof name !== "string" || name === "") {
|
|
259
310
|
throw new TypeError("You must supply a name when creating a logger.");
|
|
260
311
|
}
|
|
261
312
|
var logger = _loggersByName[name];
|
|
262
313
|
if (!logger) {
|
|
263
|
-
logger = _loggersByName[name] = new Logger(name, defaultLogger.
|
|
314
|
+
logger = _loggersByName[name] = new Logger(name, defaultLogger.methodFactory);
|
|
264
315
|
}
|
|
265
316
|
return logger;
|
|
266
317
|
};
|
|
@@ -346,7 +397,8 @@ const commands = {
|
|
|
346
397
|
nativeShare: 'nativeShareDialog',
|
|
347
398
|
langInfos: 'getLanguageInfos',
|
|
348
399
|
branchDefaultLang: 'getBranchDefaultLanguage',
|
|
349
|
-
prefContentLang: 'getPreferredContentLocale'
|
|
400
|
+
prefContentLang: 'getPreferredContentLocale',
|
|
401
|
+
userContentLocale: 'getUserContentLocale'
|
|
350
402
|
};
|
|
351
403
|
|
|
352
404
|
/**
|
|
@@ -444,6 +496,12 @@ var locales = {
|
|
|
444
496
|
name: 'English',
|
|
445
497
|
localizedName: 'English'
|
|
446
498
|
},
|
|
499
|
+
enGB: {
|
|
500
|
+
key: 'enGB',
|
|
501
|
+
locale: 'en_GB',
|
|
502
|
+
name: 'English (United Kingdom)',
|
|
503
|
+
localizedName: 'English (United Kingdom)'
|
|
504
|
+
},
|
|
447
505
|
es: {
|
|
448
506
|
key: 'es',
|
|
449
507
|
locale: 'es_ES',
|
|
@@ -935,6 +993,16 @@ const getPreferredContentLocale$2 = content => {
|
|
|
935
993
|
}
|
|
936
994
|
};
|
|
937
995
|
|
|
996
|
+
/**
|
|
997
|
+
* Get the current user's content locale, fallback to branch default locale
|
|
998
|
+
*
|
|
999
|
+
* @return {String} the user's content locale
|
|
1000
|
+
*/
|
|
1001
|
+
const getUserContentLocale$2 = () => {
|
|
1002
|
+
const locale = getBranchDefaultLanguage$2().locale;
|
|
1003
|
+
return locale;
|
|
1004
|
+
};
|
|
1005
|
+
|
|
938
1006
|
let connection$1 = null;
|
|
939
1007
|
const fallbackKickIn = 500;
|
|
940
1008
|
|
|
@@ -945,7 +1013,7 @@ const fallbackKickIn = 500;
|
|
|
945
1013
|
* after the time specified in fallbackKickIn runs out.
|
|
946
1014
|
* @return {Promise<function>} An appropriate send function
|
|
947
1015
|
*/
|
|
948
|
-
var fallback = (
|
|
1016
|
+
var fallback = () => {
|
|
949
1017
|
if (connection$1) {
|
|
950
1018
|
return connection$1;
|
|
951
1019
|
}
|
|
@@ -955,7 +1023,7 @@ var fallback = (() => {
|
|
|
955
1023
|
}, fallbackKickIn);
|
|
956
1024
|
});
|
|
957
1025
|
return connection$1;
|
|
958
|
-
}
|
|
1026
|
+
};
|
|
959
1027
|
|
|
960
1028
|
/**
|
|
961
1029
|
* Send a SDK command to the Staffbase App.
|
|
@@ -989,6 +1057,8 @@ const sendMessage$2 = async function (cmd) {
|
|
|
989
1057
|
return getBranchDefaultLanguage$2();
|
|
990
1058
|
case commands.prefContentLang:
|
|
991
1059
|
return getPreferredContentLocale$2.apply(null, payload);
|
|
1060
|
+
case commands.userContentLocale:
|
|
1061
|
+
return getUserContentLocale$2();
|
|
992
1062
|
case commands.nativeUpload:
|
|
993
1063
|
case commands.nativeShare:
|
|
994
1064
|
return unSupported();
|
|
@@ -1011,7 +1081,6 @@ var protocol = {
|
|
|
1011
1081
|
// send this to call a function in the frontend
|
|
1012
1082
|
ERROR: 'ERROR' // receive this when something goes wrong
|
|
1013
1083
|
};
|
|
1014
|
-
|
|
1015
1084
|
const invocationMapping = {
|
|
1016
1085
|
[commands.openLink]: 'openLink',
|
|
1017
1086
|
[commands.nativeUpload]: 'nativeFileUpload',
|
|
@@ -1447,6 +1516,15 @@ const getPreferredContentLocale$1 = async content => {
|
|
|
1447
1516
|
return sendMessage(commands.prefContentLang, content);
|
|
1448
1517
|
};
|
|
1449
1518
|
|
|
1519
|
+
/**
|
|
1520
|
+
* Get the default content language configured for the branch.
|
|
1521
|
+
*
|
|
1522
|
+
* @return {Promise<Object>}
|
|
1523
|
+
*/
|
|
1524
|
+
const getUserContentLocale$1 = async () => {
|
|
1525
|
+
return sendMessage(commands.langInfos).then(res => res.userContentLocale);
|
|
1526
|
+
};
|
|
1527
|
+
|
|
1450
1528
|
/**
|
|
1451
1529
|
* Compare [semver](https://semver.org/) version strings to find greater, equal or lesser.
|
|
1452
1530
|
* This library supports the full semver specification, including comparing versions with different number of digits like `1.0.0`, `1.0`, `1`, and pre-release versions like `1.0.0-alpha`.
|
|
@@ -1653,6 +1731,13 @@ const getContentLanguages = async () => getContentLanguages$1();
|
|
|
1653
1731
|
*/
|
|
1654
1732
|
const getPreferredContentLocale = async content => getPreferredContentLocale$1(content);
|
|
1655
1733
|
|
|
1734
|
+
/**
|
|
1735
|
+
* Get the current user's content locale, fallback to branch default locale
|
|
1736
|
+
* @function
|
|
1737
|
+
* @return {Promise<any>}
|
|
1738
|
+
*/
|
|
1739
|
+
const getUserContentLocale = async () => getUserContentLocale$1();
|
|
1740
|
+
|
|
1656
1741
|
/**
|
|
1657
1742
|
* Open a share dialog on native devices
|
|
1658
1743
|
*
|
|
@@ -1671,5 +1756,5 @@ const getPreferredContentLocale = async content => getPreferredContentLocale$1(c
|
|
|
1671
1756
|
const openNativeShareDialog = async content => openNativeShareDialog$1(content);
|
|
1672
1757
|
/* experimental */
|
|
1673
1758
|
|
|
1674
|
-
export { deviceCanDownload, getAppVersion, getBranchDefaultLanguage, getBranchLanguages, getContentLanguages, getPreferredContentLocale, isAndroidDevice, isIosDevice, isMobileApp, isNativeApp, openLink, openLinkExternal, openLinkInternal, openNativeFileDialog, openNativeShareDialog };
|
|
1759
|
+
export { deviceCanDownload, getAppVersion, getBranchDefaultLanguage, getBranchLanguages, getContentLanguages, getPreferredContentLocale, getUserContentLocale, isAndroidDevice, isIosDevice, isMobileApp, isNativeApp, openLink, openLinkExternal, openLinkInternal, openNativeFileDialog, openNativeShareDialog };
|
|
1675
1760
|
//# sourceMappingURL=plugins-client-sdk.esm.js.map
|