@timpel/forumkit-sdk-web 0.2.5 → 0.2.7
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/{chunk-BPIUCDZG.js → chunk-IFY5EDCC.js} +45 -7
- package/dist/chunk-IFY5EDCC.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -1
- package/dist/wrappers/react.d.ts +1 -1
- package/dist/wrappers/react.js +4 -3
- package/dist/wrappers/react.js.map +1 -1
- package/dist/wrappers/vue.d.ts +9 -0
- package/dist/wrappers/vue.js +3 -1
- package/dist/wrappers/vue.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-BPIUCDZG.js.map +0 -1
|
@@ -392,11 +392,12 @@ function SessionProvider({ config, children }) {
|
|
|
392
392
|
if (cancelled) return;
|
|
393
393
|
expiresAtRef.current = Date.now() + expiresIn * 1e3;
|
|
394
394
|
refreshTimer = setTimeout(() => {
|
|
395
|
-
void refresh();
|
|
395
|
+
void refresh(true);
|
|
396
396
|
}, expiresIn * 1e3 * 0.8);
|
|
397
397
|
}
|
|
398
|
-
function refresh() {
|
|
399
|
-
|
|
398
|
+
function refresh(isRenewal = false) {
|
|
399
|
+
const tokenPromise = isRenewal && config.getToken ? config.getToken() : Promise.resolve(config.token);
|
|
400
|
+
return tokenPromise.then((hostToken) => createSession2(apiUrl, hostToken)).then((result) => {
|
|
400
401
|
if (cancelled) return;
|
|
401
402
|
setState({ status: "ready", forumId: config.forumId, apiUrl, sessionToken: result.sessionToken, error: null, onLogout: config.onLogout, platform });
|
|
402
403
|
scheduleRefresh(result.expiresIn);
|
|
@@ -405,7 +406,7 @@ function SessionProvider({ config, children }) {
|
|
|
405
406
|
const message = err instanceof Error ? err.message : "Failed to create session";
|
|
406
407
|
setState({ status: "error", forumId: config.forumId, apiUrl, sessionToken: null, error: message, onLogout: config.onLogout, platform });
|
|
407
408
|
retryTimer = setTimeout(() => {
|
|
408
|
-
void refresh();
|
|
409
|
+
void refresh(true);
|
|
409
410
|
}, RETRY_DELAY_MS);
|
|
410
411
|
});
|
|
411
412
|
}
|
|
@@ -413,7 +414,7 @@ function SessionProvider({ config, children }) {
|
|
|
413
414
|
if (document.visibilityState !== "visible") return;
|
|
414
415
|
const msRemaining = expiresAtRef.current - Date.now();
|
|
415
416
|
if (msRemaining <= 0) {
|
|
416
|
-
void refresh();
|
|
417
|
+
void refresh(true);
|
|
417
418
|
} else {
|
|
418
419
|
if (refreshTimer) clearTimeout(refreshTimer);
|
|
419
420
|
scheduleRefresh(msRemaining / 1e3);
|
|
@@ -13338,6 +13339,23 @@ button.fk-profile-filter-label {
|
|
|
13338
13339
|
|
|
13339
13340
|
// src/components/forum-kit.ts
|
|
13340
13341
|
var DEFAULT_API_URL = "";
|
|
13342
|
+
var FONTS_HREF = "https://fonts.googleapis.com/css2?family=Michroma&family=Inter:wght@400;500;600;700;800&display=swap";
|
|
13343
|
+
function ensureFontsLoaded() {
|
|
13344
|
+
if (document.querySelector(`link[href="${FONTS_HREF}"]`)) return;
|
|
13345
|
+
const preconnect1 = document.createElement("link");
|
|
13346
|
+
preconnect1.rel = "preconnect";
|
|
13347
|
+
preconnect1.href = "https://fonts.googleapis.com";
|
|
13348
|
+
document.head.appendChild(preconnect1);
|
|
13349
|
+
const preconnect2 = document.createElement("link");
|
|
13350
|
+
preconnect2.rel = "preconnect";
|
|
13351
|
+
preconnect2.href = "https://fonts.gstatic.com";
|
|
13352
|
+
preconnect2.crossOrigin = "anonymous";
|
|
13353
|
+
document.head.appendChild(preconnect2);
|
|
13354
|
+
const stylesheet = document.createElement("link");
|
|
13355
|
+
stylesheet.rel = "stylesheet";
|
|
13356
|
+
stylesheet.href = FONTS_HREF;
|
|
13357
|
+
document.head.appendChild(stylesheet);
|
|
13358
|
+
}
|
|
13341
13359
|
var ForumKitElement = class extends HTMLElement {
|
|
13342
13360
|
_config = null;
|
|
13343
13361
|
_shadow;
|
|
@@ -13358,11 +13376,30 @@ var ForumKitElement = class extends HTMLElement {
|
|
|
13358
13376
|
this._render();
|
|
13359
13377
|
}
|
|
13360
13378
|
}
|
|
13379
|
+
// Same reasoning as onLogout above - getToken is a function, so it's a JS
|
|
13380
|
+
// property (el.getToken = fn) rather than an observed attribute. Called by
|
|
13381
|
+
// SessionProvider to fetch a fresh host JWT on every renewal past the
|
|
13382
|
+
// first exchange, since a properly short-lived host token (the security
|
|
13383
|
+
// property it's meant to have) will already be expired by the time a
|
|
13384
|
+
// renewal is due - without this, the SDK has no way to get a new one and
|
|
13385
|
+
// renewal just fails once the original token expires.
|
|
13386
|
+
_getToken;
|
|
13387
|
+
get getToken() {
|
|
13388
|
+
return this._getToken;
|
|
13389
|
+
}
|
|
13390
|
+
set getToken(fn) {
|
|
13391
|
+
this._getToken = fn;
|
|
13392
|
+
if (this._config) {
|
|
13393
|
+
this._config = this._readConfig();
|
|
13394
|
+
this._render();
|
|
13395
|
+
}
|
|
13396
|
+
}
|
|
13361
13397
|
static get observedAttributes() {
|
|
13362
13398
|
return ["forum-id", "token", "theme", "api-url", "platform"];
|
|
13363
13399
|
}
|
|
13364
13400
|
constructor() {
|
|
13365
13401
|
super();
|
|
13402
|
+
ensureFontsLoaded();
|
|
13366
13403
|
this._shadow = this.attachShadow({ mode: "open" });
|
|
13367
13404
|
const style = document.createElement("style");
|
|
13368
13405
|
style.textContent = all_default;
|
|
@@ -13406,7 +13443,8 @@ var ForumKitElement = class extends HTMLElement {
|
|
|
13406
13443
|
theme,
|
|
13407
13444
|
apiUrl,
|
|
13408
13445
|
platform,
|
|
13409
|
-
...this._onLogout ? { onLogout: this._onLogout } : {}
|
|
13446
|
+
...this._onLogout ? { onLogout: this._onLogout } : {},
|
|
13447
|
+
...this._getToken ? { getToken: this._getToken } : {}
|
|
13410
13448
|
};
|
|
13411
13449
|
}
|
|
13412
13450
|
/**
|
|
@@ -13459,4 +13497,4 @@ if (!customElements.get("forum-kit")) {
|
|
|
13459
13497
|
export {
|
|
13460
13498
|
ForumKitElement
|
|
13461
13499
|
};
|
|
13462
|
-
//# sourceMappingURL=chunk-
|
|
13500
|
+
//# sourceMappingURL=chunk-IFY5EDCC.js.map
|