@akc42/app-utils 3.1.5 → 3.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.
- package/README.md +3 -5
- package/debug.js +15 -11
- package/package.json +1 -1
- package/post-api.js +5 -3
package/README.md
CHANGED
|
@@ -134,11 +134,9 @@ The purpose of this module is to provide a debugable capability which can be
|
|
|
134
134
|
config-promise) is set to a string which is a comma separated list of topics
|
|
135
135
|
and that list has the topic for this debug call in it.
|
|
136
136
|
|
|
137
|
-
**Note**: the debug function checks with the
|
|
138
|
-
to see if the topic is enabled
|
|
139
|
-
|
|
140
|
-
change what topics are available and for the client side to quickly find if it
|
|
141
|
-
should now start sending message
|
|
137
|
+
**Note**: the debug function checks with the sessionStorage.getItem('debug) (via an await for the Config Promise)
|
|
138
|
+
to see if the topic is enabled (assumes the result is a ':' separated string of topics). This allows the server to
|
|
139
|
+
change what topics are available via the config api call.
|
|
142
140
|
|
|
143
141
|
# dom-host
|
|
144
142
|
|
package/debug.js
CHANGED
|
@@ -53,10 +53,11 @@
|
|
|
53
53
|
would dynamically pick up the changes
|
|
54
54
|
|
|
55
55
|
*/
|
|
56
|
+
import config from './config-promise.js';
|
|
56
57
|
|
|
57
58
|
const topicMap = new Map();
|
|
58
59
|
|
|
59
|
-
|
|
60
|
+
|
|
60
61
|
|
|
61
62
|
function Debug (t) {
|
|
62
63
|
if (typeof t !== 'string' || t.length === 0 || !/^[a-zA-Z]+$/.test(t)) {
|
|
@@ -64,7 +65,6 @@ function Debug (t) {
|
|
|
64
65
|
throw new Error('Invalid Debug Topic');
|
|
65
66
|
}
|
|
66
67
|
const tl = t.toLowerCase();
|
|
67
|
-
|
|
68
68
|
if (topicMap.has(tl) ) {
|
|
69
69
|
const topic = topicMap.get(tl);
|
|
70
70
|
return topic.debug;
|
|
@@ -73,21 +73,25 @@ function Debug (t) {
|
|
|
73
73
|
const topicHandler = {
|
|
74
74
|
topic: tl,
|
|
75
75
|
timestamp: new Date().getTime(),
|
|
76
|
-
|
|
77
|
-
enabled: false, //is this topic enabled
|
|
76
|
+
defined: false, //has the config been defined yet
|
|
78
77
|
debug: async function (...args) {
|
|
79
78
|
//do time calc before potential delay to see if we are enabled
|
|
80
79
|
const now = new Date().getTime();
|
|
81
80
|
const gap = now - this.timestamp;
|
|
82
81
|
this.timestamp = now;
|
|
83
|
-
if (
|
|
84
|
-
//
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
82
|
+
if (!this.defined) {
|
|
83
|
+
//just await the config the first time through. Thereafter we can assume its done
|
|
84
|
+
await config();
|
|
85
|
+
this.defined = true;
|
|
86
|
+
}
|
|
87
|
+
let enabled = false;
|
|
88
|
+
const debugConf = sessionStorage.getItem('debug');
|
|
89
|
+
if (debugConf) {
|
|
90
|
+
const topics = debugConf.split(':');
|
|
91
|
+
if (topics.includes(this.topic)) enabled = true;
|
|
89
92
|
}
|
|
90
|
-
|
|
93
|
+
|
|
94
|
+
if (enabled) {
|
|
91
95
|
const message = args.reduce((cum, arg) => {
|
|
92
96
|
return `${cum} ${arg}`.trim();
|
|
93
97
|
}, '');
|
package/package.json
CHANGED
package/post-api.js
CHANGED
|
@@ -47,8 +47,10 @@ export default async function api(url, params, blob, signal) {
|
|
|
47
47
|
return {};
|
|
48
48
|
}
|
|
49
49
|
} catch (err) {
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
if (!options.signal || !options.signal.aborted) {
|
|
51
|
+
if (err.type === 'api-error') throw err; //just throw whatever error we had
|
|
52
|
+
//we failed to parse the json - the actual code should be in the text near the end;
|
|
53
|
+
throw new CustomEvent('api-error', { composed: true, bubbles: true, detail: parseInt((text?? '---502---').slice(-6, -3), 10) });
|
|
54
|
+
}
|
|
53
55
|
}
|
|
54
56
|
}
|