obi-sdk 0.10.0 → 0.11.1
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/modular/chunks/index-45f4d445.js +6 -0
- package/dist/modular/chunks/index-45f4d445.js.map +1 -0
- package/dist/modular/chunks/{obi-widget-d8d64ad7.js → obi-widget-00df4624.js} +207 -19
- package/dist/modular/chunks/obi-widget-00df4624.js.map +1 -0
- package/dist/modular/index.js +1 -1
- package/dist/modular/ui.js +10 -10
- package/dist/obi-sdk.standalone.iife.js +31 -31
- package/dist/obi-sdk.standalone.iife.js.map +1 -1
- package/dist/react.es.js +1266 -1151
- package/dist/react.es.js.map +1 -1
- package/dist/react.umd.js +68 -68
- package/dist/react.umd.js.map +1 -1
- package/dist/ui/components/obi-widget/obi-widget.d.ts +11 -0
- package/package.json +1 -1
- package/dist/modular/chunks/index-e3a03e58.js +0 -6
- package/dist/modular/chunks/index-e3a03e58.js.map +0 -1
- package/dist/modular/chunks/obi-widget-d8d64ad7.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-45f4d445.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -460,6 +460,12 @@ class ObiClient {
|
|
|
460
460
|
params: { path: { id } }
|
|
461
461
|
});
|
|
462
462
|
}
|
|
463
|
+
async getOnboardeeWidgetConfig(id, signal) {
|
|
464
|
+
return await this.client.GET("/onboardees/{id}/config", {
|
|
465
|
+
params: { path: { id } },
|
|
466
|
+
signal
|
|
467
|
+
});
|
|
468
|
+
}
|
|
463
469
|
// Plans
|
|
464
470
|
async listPlans() {
|
|
465
471
|
return await this.client.GET("/plans");
|
|
@@ -468,6 +474,17 @@ class ObiClient {
|
|
|
468
474
|
async listProducts() {
|
|
469
475
|
return await this.client.GET("/products");
|
|
470
476
|
}
|
|
477
|
+
async createProduct(data) {
|
|
478
|
+
return await this.client.POST("/products", {
|
|
479
|
+
body: data
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
async updateProduct(id, data) {
|
|
483
|
+
return await this.client.PATCH("/products/{id}", {
|
|
484
|
+
params: { path: { id } },
|
|
485
|
+
body: data
|
|
486
|
+
});
|
|
487
|
+
}
|
|
471
488
|
async createPlan(data) {
|
|
472
489
|
return await this.client.POST("/plans", {
|
|
473
490
|
body: data
|
|
@@ -495,6 +512,44 @@ class ObiClient {
|
|
|
495
512
|
params: { path: { id } }
|
|
496
513
|
});
|
|
497
514
|
}
|
|
515
|
+
async deletePlan(id) {
|
|
516
|
+
return await this.client.DELETE("/admin/plans/{id}", {
|
|
517
|
+
params: { path: { id } }
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
async publishPlanRevision(id, data) {
|
|
521
|
+
return await this.client.POST("/plans/{id}/publish", {
|
|
522
|
+
params: { path: { id } },
|
|
523
|
+
body: data
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
async listPlanRevisions(id) {
|
|
527
|
+
return await this.client.GET("/plans/{id}/revisions", {
|
|
528
|
+
params: { path: { id } }
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
async getRevisionNavigationIndex(revisionId) {
|
|
532
|
+
return await this.client.GET("/revisions/{id}/navigation-index", {
|
|
533
|
+
params: { path: { id: revisionId } }
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
async replaceRevisionNavigationIndex(revisionId, data) {
|
|
537
|
+
return await this.client.PUT("/revisions/{id}/navigation-index", {
|
|
538
|
+
params: { path: { id: revisionId } },
|
|
539
|
+
body: data
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
async getRevisionFAQ(revisionId) {
|
|
543
|
+
return await this.client.GET("/revisions/{id}/faq", {
|
|
544
|
+
params: { path: { id: revisionId } }
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
async replaceRevisionFAQ(revisionId, data) {
|
|
548
|
+
return await this.client.PUT("/revisions/{id}/faq", {
|
|
549
|
+
params: { path: { id: revisionId } },
|
|
550
|
+
body: data
|
|
551
|
+
});
|
|
552
|
+
}
|
|
498
553
|
// Sessions
|
|
499
554
|
async listSessions(token) {
|
|
500
555
|
return await this.client.GET("/sessions", {
|
|
@@ -16056,8 +16111,8 @@ function isCurrentUrlBlacklisted(blacklist) {
|
|
|
16056
16111
|
if (!blacklist || blacklist.length === 0) {
|
|
16057
16112
|
return false;
|
|
16058
16113
|
}
|
|
16059
|
-
const
|
|
16060
|
-
return matchesUrlPattern(
|
|
16114
|
+
const pathOnlyUrl = window.location.origin + window.location.pathname;
|
|
16115
|
+
return matchesUrlPattern(pathOnlyUrl, blacklist);
|
|
16061
16116
|
}
|
|
16062
16117
|
var __defProp$7 = Object.defineProperty;
|
|
16063
16118
|
var __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor;
|
|
@@ -17926,6 +17981,9 @@ class ObiWidget extends i$1 {
|
|
|
17926
17981
|
volume: 0,
|
|
17927
17982
|
spectrum: []
|
|
17928
17983
|
};
|
|
17984
|
+
this.databaseConfig = null;
|
|
17985
|
+
this.configLoaded = false;
|
|
17986
|
+
this.configAllInCode = false;
|
|
17929
17987
|
this.sessionToken = null;
|
|
17930
17988
|
this.roomToken = null;
|
|
17931
17989
|
this.roomUrl = null;
|
|
@@ -17933,6 +17991,8 @@ class ObiWidget extends i$1 {
|
|
|
17933
17991
|
this.obiClient = null;
|
|
17934
17992
|
this.closeNavTimeoutRef = null;
|
|
17935
17993
|
this.researchingTimeoutRef = null;
|
|
17994
|
+
this.urlCheckInterval = null;
|
|
17995
|
+
this.currentUrl = "";
|
|
17936
17996
|
this.connectObi = withSentryAsyncHandler(
|
|
17937
17997
|
async (sessionToken) => {
|
|
17938
17998
|
if (this.activeSession) {
|
|
@@ -18188,6 +18248,7 @@ class ObiWidget extends i$1 {
|
|
|
18188
18248
|
this.obiClient = new ObiClient({
|
|
18189
18249
|
baseUrl: API_BASE_URL
|
|
18190
18250
|
});
|
|
18251
|
+
this.currentUrl = window.location.href;
|
|
18191
18252
|
const handleUnload = () => {
|
|
18192
18253
|
try {
|
|
18193
18254
|
if (this.activeSession && this.sessionToken && this.roomToken && this.roomUrl) {
|
|
@@ -18205,29 +18266,49 @@ class ObiWidget extends i$1 {
|
|
|
18205
18266
|
throw error;
|
|
18206
18267
|
}
|
|
18207
18268
|
}
|
|
18208
|
-
// Method to get values from window.obiWidgetConfig
|
|
18209
18269
|
updateFromConfig() {
|
|
18210
18270
|
if (window.obiWidgetConfig) {
|
|
18211
18271
|
this.apiKey = window.obiWidgetConfig.apiKey || this.apiKey;
|
|
18212
|
-
|
|
18213
|
-
|
|
18214
|
-
|
|
18215
|
-
this.urlBlacklist = window.obiWidgetConfig.urlBlacklist || [];
|
|
18272
|
+
if (window.obiWidgetConfig.position !== void 0) {
|
|
18273
|
+
this.position = window.obiWidgetConfig.position;
|
|
18274
|
+
this.setAttribute("position", this.position);
|
|
18216
18275
|
}
|
|
18217
|
-
if (window.obiWidgetConfig.
|
|
18218
|
-
this.
|
|
18276
|
+
if (window.obiWidgetConfig.primaryColor !== void 0) {
|
|
18277
|
+
this.style.setProperty("--obi-primary", window.obiWidgetConfig.primaryColor);
|
|
18278
|
+
this.generateColorVariables(window.obiWidgetConfig.primaryColor);
|
|
18279
|
+
}
|
|
18280
|
+
if (window.obiWidgetConfig.user !== void 0) {
|
|
18281
|
+
this.user = window.obiWidgetConfig.user;
|
|
18219
18282
|
}
|
|
18220
18283
|
if (window.obiWidgetConfig.isActive !== void 0) {
|
|
18221
18284
|
this.isActive = window.obiWidgetConfig.isActive;
|
|
18222
18285
|
}
|
|
18286
|
+
if (window.obiWidgetConfig.linkOnlyAccess !== void 0) {
|
|
18287
|
+
this.linkOnlyAccess = window.obiWidgetConfig.linkOnlyAccess;
|
|
18288
|
+
}
|
|
18289
|
+
if (window.obiWidgetConfig.urlBlacklist !== void 0) {
|
|
18290
|
+
this.urlBlacklist = window.obiWidgetConfig.urlBlacklist;
|
|
18291
|
+
}
|
|
18292
|
+
const hasPosition = window.obiWidgetConfig.position !== void 0;
|
|
18293
|
+
const hasPrimaryColor = window.obiWidgetConfig.primaryColor !== void 0;
|
|
18294
|
+
const hasLinkOnlyAccess = window.obiWidgetConfig.linkOnlyAccess !== void 0;
|
|
18295
|
+
const hasUrlBlacklist = window.obiWidgetConfig.urlBlacklist !== void 0;
|
|
18296
|
+
this.configAllInCode = hasPosition && hasPrimaryColor && hasLinkOnlyAccess && hasUrlBlacklist;
|
|
18297
|
+
if (this.configAllInCode) {
|
|
18298
|
+
this.configLoaded = true;
|
|
18299
|
+
this.applyFinalConfiguration();
|
|
18300
|
+
} else if (!this.configLoaded) {
|
|
18301
|
+
this.fetchDatabaseConfig();
|
|
18302
|
+
}
|
|
18223
18303
|
if (window.obiWidgetConfig.showMenu === true) {
|
|
18224
18304
|
this.state = SDKState.LOADING;
|
|
18225
18305
|
this.showCourseModal = true;
|
|
18226
18306
|
window.obiWidgetConfig.showMenu = false;
|
|
18227
18307
|
}
|
|
18228
|
-
|
|
18229
|
-
this.
|
|
18230
|
-
|
|
18308
|
+
} else {
|
|
18309
|
+
if (!this.configLoaded) {
|
|
18310
|
+
this.fetchDatabaseConfig();
|
|
18311
|
+
}
|
|
18231
18312
|
}
|
|
18232
18313
|
}
|
|
18233
18314
|
/**
|
|
@@ -18332,6 +18413,15 @@ class ObiWidget extends i$1 {
|
|
|
18332
18413
|
clearSessionStorage() {
|
|
18333
18414
|
storage.removeItem(STORAGE_KEYS.SESSION_DATA);
|
|
18334
18415
|
}
|
|
18416
|
+
/**
|
|
18417
|
+
* Handle URL changes to check if the new URL is blacklisted
|
|
18418
|
+
*/
|
|
18419
|
+
handleUrlChange() {
|
|
18420
|
+
this.requestUpdate();
|
|
18421
|
+
if (isCurrentUrlBlacklisted(this.urlBlacklist) && this.activeSession) {
|
|
18422
|
+
this.terminateSession();
|
|
18423
|
+
}
|
|
18424
|
+
}
|
|
18335
18425
|
// Method to save session data
|
|
18336
18426
|
saveSessionData() {
|
|
18337
18427
|
if (!this.activeSession)
|
|
@@ -18386,10 +18476,15 @@ class ObiWidget extends i$1 {
|
|
|
18386
18476
|
this.boundSaveSessionData = this.saveSessionData.bind(this);
|
|
18387
18477
|
window.addEventListener("beforeunload", this.boundSaveSessionData);
|
|
18388
18478
|
window.addEventListener("pagehide", this.boundSaveSessionData);
|
|
18389
|
-
|
|
18390
|
-
|
|
18391
|
-
|
|
18479
|
+
if (this.isActive) {
|
|
18480
|
+
this.urlCheckInterval = window.setInterval(() => {
|
|
18481
|
+
if (this.currentUrl !== window.location.href) {
|
|
18482
|
+
this.currentUrl = window.location.href;
|
|
18483
|
+
this.handleUrlChange();
|
|
18484
|
+
}
|
|
18485
|
+
}, 1e3);
|
|
18392
18486
|
}
|
|
18487
|
+
this.addEventListener("course-select", this.handleCourseSelectEvent);
|
|
18393
18488
|
}
|
|
18394
18489
|
disconnectedCallback() {
|
|
18395
18490
|
super.disconnectedCallback();
|
|
@@ -18405,6 +18500,10 @@ class ObiWidget extends i$1 {
|
|
|
18405
18500
|
window.removeEventListener("beforeunload", this.boundSaveSessionData);
|
|
18406
18501
|
window.removeEventListener("pagehide", this.boundSaveSessionData);
|
|
18407
18502
|
}
|
|
18503
|
+
if (this.urlCheckInterval !== null) {
|
|
18504
|
+
clearInterval(this.urlCheckInterval);
|
|
18505
|
+
this.urlCheckInterval = null;
|
|
18506
|
+
}
|
|
18408
18507
|
this.removeSessionUrlParams();
|
|
18409
18508
|
}
|
|
18410
18509
|
handleConfigUpdate(event) {
|
|
@@ -18412,9 +18511,6 @@ class ObiWidget extends i$1 {
|
|
|
18412
18511
|
const updatedConfig = customEvent.detail;
|
|
18413
18512
|
const needsInit = updatedConfig.isActive && !this.isActive;
|
|
18414
18513
|
this.updateFromConfig();
|
|
18415
|
-
if (this.position) {
|
|
18416
|
-
this.setAttribute("position", this.position);
|
|
18417
|
-
}
|
|
18418
18514
|
if (needsInit && !isCurrentUrlBlacklisted(this.urlBlacklist)) {
|
|
18419
18515
|
this.sessionConnectionCheck();
|
|
18420
18516
|
}
|
|
@@ -18470,7 +18566,90 @@ class ObiWidget extends i$1 {
|
|
|
18470
18566
|
return;
|
|
18471
18567
|
});
|
|
18472
18568
|
}
|
|
18569
|
+
async fetchDatabaseConfig() {
|
|
18570
|
+
if (!this.apiKey) {
|
|
18571
|
+
this.configLoaded = true;
|
|
18572
|
+
this.applyFinalConfiguration();
|
|
18573
|
+
return;
|
|
18574
|
+
}
|
|
18575
|
+
try {
|
|
18576
|
+
const cacheKey = `obi-widget-config-${this.apiKey}`;
|
|
18577
|
+
const cachedConfig = localStorage.getItem(cacheKey);
|
|
18578
|
+
const cacheTimestamp = localStorage.getItem(`${cacheKey}-timestamp`);
|
|
18579
|
+
if (cachedConfig && cacheTimestamp) {
|
|
18580
|
+
const age = Date.now() - parseInt(cacheTimestamp, 10);
|
|
18581
|
+
const maxAge = 10 * 60 * 1e3;
|
|
18582
|
+
if (age < maxAge) {
|
|
18583
|
+
const dbConfig2 = JSON.parse(cachedConfig);
|
|
18584
|
+
this.databaseConfig = dbConfig2;
|
|
18585
|
+
this.configLoaded = true;
|
|
18586
|
+
this.applyFinalConfiguration();
|
|
18587
|
+
return;
|
|
18588
|
+
}
|
|
18589
|
+
}
|
|
18590
|
+
const controller = new AbortController();
|
|
18591
|
+
const timeoutId = setTimeout(() => controller.abort(), 3e3);
|
|
18592
|
+
const result = await this.obiClient.getOnboardeeWidgetConfig(this.apiKey, controller.signal);
|
|
18593
|
+
clearTimeout(timeoutId);
|
|
18594
|
+
if (result.error) {
|
|
18595
|
+
if (result.response?.status === 404) {
|
|
18596
|
+
localStorage.removeItem(cacheKey);
|
|
18597
|
+
localStorage.removeItem(`${cacheKey}-timestamp`);
|
|
18598
|
+
this.databaseConfig = null;
|
|
18599
|
+
this.configLoaded = true;
|
|
18600
|
+
this.applyFinalConfiguration();
|
|
18601
|
+
return;
|
|
18602
|
+
}
|
|
18603
|
+
throw new Error(`HTTP ${result.response?.status || "Unknown error"}`);
|
|
18604
|
+
}
|
|
18605
|
+
const dbConfig = result.data;
|
|
18606
|
+
localStorage.setItem(cacheKey, JSON.stringify(dbConfig));
|
|
18607
|
+
localStorage.setItem(`${cacheKey}-timestamp`, Date.now().toString());
|
|
18608
|
+
this.databaseConfig = dbConfig;
|
|
18609
|
+
this.configLoaded = true;
|
|
18610
|
+
this.applyFinalConfiguration();
|
|
18611
|
+
} catch (error) {
|
|
18612
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
18613
|
+
console.warn("Widget config fetch timed out, using defaults");
|
|
18614
|
+
} else {
|
|
18615
|
+
console.warn("Failed to fetch widget config from database:", error);
|
|
18616
|
+
}
|
|
18617
|
+
this.databaseConfig = null;
|
|
18618
|
+
this.configLoaded = true;
|
|
18619
|
+
this.applyFinalConfiguration();
|
|
18620
|
+
}
|
|
18621
|
+
}
|
|
18622
|
+
// Apply final configuration by merging code config (priority) with database config
|
|
18623
|
+
applyFinalConfiguration() {
|
|
18624
|
+
const windowConfig = window.obiWidgetConfig;
|
|
18625
|
+
const dbConfig = this.databaseConfig;
|
|
18626
|
+
this.user = windowConfig?.user || this.user;
|
|
18627
|
+
this.position = windowConfig?.position || dbConfig?.position || this.position;
|
|
18628
|
+
this.setAttribute("position", this.position);
|
|
18629
|
+
if (windowConfig?.isActive !== void 0) {
|
|
18630
|
+
this.isActive = windowConfig.isActive;
|
|
18631
|
+
}
|
|
18632
|
+
if (windowConfig?.linkOnlyAccess !== void 0) {
|
|
18633
|
+
this.linkOnlyAccess = windowConfig.linkOnlyAccess;
|
|
18634
|
+
} else if (dbConfig?.linkOnlyAccess !== void 0) {
|
|
18635
|
+
this.linkOnlyAccess = dbConfig.linkOnlyAccess;
|
|
18636
|
+
}
|
|
18637
|
+
const codeBlacklist = windowConfig?.urlBlacklist || [];
|
|
18638
|
+
const dbBlacklist = dbConfig?.urlBlacklist || [];
|
|
18639
|
+
if (codeBlacklist.length > 0 || dbBlacklist.length > 0) {
|
|
18640
|
+
const merged = [...codeBlacklist, ...dbBlacklist];
|
|
18641
|
+
this.urlBlacklist = [...new Set(merged)];
|
|
18642
|
+
}
|
|
18643
|
+
const primaryColor = windowConfig?.primaryColor || dbConfig?.primaryColor || OBI_PRIMARY_COLOR;
|
|
18644
|
+
this.style.setProperty("--obi-primary", primaryColor);
|
|
18645
|
+
this.generateColorVariables(primaryColor);
|
|
18646
|
+
if (this.isActive && !isCurrentUrlBlacklisted(this.urlBlacklist)) {
|
|
18647
|
+
this.sessionConnectionCheck();
|
|
18648
|
+
}
|
|
18649
|
+
}
|
|
18473
18650
|
render() {
|
|
18651
|
+
if (!this.configLoaded)
|
|
18652
|
+
return E;
|
|
18474
18653
|
if (!this.isActive)
|
|
18475
18654
|
return E;
|
|
18476
18655
|
if (this.linkOnlyAccess && this.state === SDKState.READY)
|
|
@@ -18726,6 +18905,15 @@ __decorateClass([
|
|
|
18726
18905
|
__decorateClass([
|
|
18727
18906
|
r$1()
|
|
18728
18907
|
], ObiWidget.prototype, "volume", 2);
|
|
18908
|
+
__decorateClass([
|
|
18909
|
+
r$1()
|
|
18910
|
+
], ObiWidget.prototype, "databaseConfig", 2);
|
|
18911
|
+
__decorateClass([
|
|
18912
|
+
r$1()
|
|
18913
|
+
], ObiWidget.prototype, "configLoaded", 2);
|
|
18914
|
+
__decorateClass([
|
|
18915
|
+
r$1()
|
|
18916
|
+
], ObiWidget.prototype, "configAllInCode", 2);
|
|
18729
18917
|
if (!customElements.get("obi-widget")) {
|
|
18730
18918
|
customElements.define("obi-widget", ObiWidget);
|
|
18731
18919
|
}
|
|
@@ -18756,4 +18944,4 @@ export {
|
|
|
18756
18944
|
withSentryAsyncHandler as w,
|
|
18757
18945
|
x
|
|
18758
18946
|
};
|
|
18759
|
-
//# sourceMappingURL=obi-widget-
|
|
18947
|
+
//# sourceMappingURL=obi-widget-00df4624.js.map
|