Skip to content

Commit 2c74047

Browse files
authored
Upd. Settings. Added fallback to spotfixConfig for incomplete URL parameters (#85)
* Upd. Settings. Added fallback to spotfixConfig for incomplete URL parameters * Fix. Settings. Fixed fallback to spotfixConfig for incomplete URL parameters.
1 parent 09ee009 commit 2c74047

4 files changed

Lines changed: 26 additions & 8 deletions

File tree

dist/doboard-widget-bundle.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9154,13 +9154,22 @@ class CleanTalkWidgetDoboard {
91549154

91559155
const url = new URL(script.src);
91569156
let params = Object.fromEntries(url.searchParams.entries());
9157-
if ( ! params ) {
9158-
throw new Error('Script params not provided');
9157+
const config = typeof window.spotfixConfig === 'object' && window.spotfixConfig ? window.spotfixConfig : null;
9158+
9159+
// Fallback to spotfixConfig when URL has no params or they are incomplete (e.g. WordPress plugin)
9160+
if ( config ) {
9161+
params = {
9162+
...params,
9163+
projectToken: params.projectToken || config.projectToken || '',
9164+
projectId: params.projectId || config.projectId || '',
9165+
accountId: params.accountId || config.accountId || ''
9166+
};
91599167
}
9168+
91609169
if ( ! params.projectToken || ! params.accountId || ! params.projectId ) {
91619170
throw new Error('Necessary script params not provided');
9162-
91639171
}
9172+
91649173
if (params.accountId) {
91659174
localStorage.setItem('spotfix_company_id', params.accountId);
91669175
}

dist/doboard-widget-bundle.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/doboard-widget-bundle.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/src/widget.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,22 @@ class CleanTalkWidgetDoboard {
115115

116116
const url = new URL(script.src);
117117
let params = Object.fromEntries(url.searchParams.entries());
118-
if ( ! params ) {
119-
throw new Error('Script params not provided');
118+
const config = typeof window.spotfixConfig === 'object' && window.spotfixConfig ? window.spotfixConfig : null;
119+
120+
// Fallback to spotfixConfig when URL has no params or they are incomplete (e.g. WordPress plugin)
121+
if ( config ) {
122+
params = {
123+
...params,
124+
projectToken: params.projectToken || config.projectToken || '',
125+
projectId: params.projectId || config.projectId || '',
126+
accountId: params.accountId || config.accountId || ''
127+
};
120128
}
129+
121130
if ( ! params.projectToken || ! params.accountId || ! params.projectId ) {
122131
throw new Error('Necessary script params not provided');
123-
124132
}
133+
125134
if (params.accountId) {
126135
localStorage.setItem('spotfix_company_id', params.accountId);
127136
}

0 commit comments

Comments
 (0)