@blocklet/js-sdk 1.17.3-beta-20251123-232619-53258789 → 1.17.3-beta-20251126-121502-d0926972
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/index.d.mts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.mjs +54 -3
- package/package.json +8 -6
package/dist/index.d.mts
CHANGED
|
@@ -335,6 +335,11 @@ declare class FederatedService {
|
|
|
335
335
|
}
|
|
336
336
|
|
|
337
337
|
declare function getCSRFToken(): string;
|
|
338
|
+
declare function getLoginToken(): string;
|
|
339
|
+
declare function getCSRFTokenByLoginToken(): Promise<{
|
|
340
|
+
loginToken: string;
|
|
341
|
+
csrfToken: string | null;
|
|
342
|
+
}>;
|
|
338
343
|
|
|
339
344
|
declare class BlockletSDK {
|
|
340
345
|
api: Axios;
|
|
@@ -351,4 +356,4 @@ declare function createFetch(options?: RequestInit, requestParams?: RequestParam
|
|
|
351
356
|
}) => Promise<Response>;
|
|
352
357
|
declare const getBlockletSDK: () => BlockletSDK;
|
|
353
358
|
|
|
354
|
-
export { AuthService, BlockletSDK, BlockletService, ComponentService, FederatedService, type NotificationConfig, OrgQueryType, type PrivacyConfig, type SpaceGateway, TokenService, type UserPublicInfo, type UserSession, type UserSessionList, type UserSessionQuery, UserSessionService, type UserSessionUser, type Webhook, createAxios, createFetch, getBlockletSDK, getCSRFToken };
|
|
359
|
+
export { AuthService, BlockletSDK, BlockletService, ComponentService, FederatedService, type NotificationConfig, OrgQueryType, type PrivacyConfig, type SpaceGateway, TokenService, type UserPublicInfo, type UserSession, type UserSessionList, type UserSessionQuery, UserSessionService, type UserSessionUser, type Webhook, createAxios, createFetch, getBlockletSDK, getCSRFToken, getCSRFTokenByLoginToken, getLoginToken };
|
package/dist/index.d.ts
CHANGED
|
@@ -335,6 +335,11 @@ declare class FederatedService {
|
|
|
335
335
|
}
|
|
336
336
|
|
|
337
337
|
declare function getCSRFToken(): string;
|
|
338
|
+
declare function getLoginToken(): string;
|
|
339
|
+
declare function getCSRFTokenByLoginToken(): Promise<{
|
|
340
|
+
loginToken: string;
|
|
341
|
+
csrfToken: string | null;
|
|
342
|
+
}>;
|
|
338
343
|
|
|
339
344
|
declare class BlockletSDK {
|
|
340
345
|
api: Axios;
|
|
@@ -351,4 +356,4 @@ declare function createFetch(options?: RequestInit, requestParams?: RequestParam
|
|
|
351
356
|
}) => Promise<Response>;
|
|
352
357
|
declare const getBlockletSDK: () => BlockletSDK;
|
|
353
358
|
|
|
354
|
-
export { AuthService, BlockletSDK, BlockletService, ComponentService, FederatedService, type NotificationConfig, OrgQueryType, type PrivacyConfig, type SpaceGateway, TokenService, type UserPublicInfo, type UserSession, type UserSessionList, type UserSessionQuery, UserSessionService, type UserSessionUser, type Webhook, createAxios, createFetch, getBlockletSDK, getCSRFToken };
|
|
359
|
+
export { AuthService, BlockletSDK, BlockletService, ComponentService, FederatedService, type NotificationConfig, OrgQueryType, type PrivacyConfig, type SpaceGateway, TokenService, type UserPublicInfo, type UserSession, type UserSessionList, type UserSessionQuery, UserSessionService, type UserSessionUser, type Webhook, createAxios, createFetch, getBlockletSDK, getCSRFToken, getCSRFTokenByLoginToken, getLoginToken };
|
package/dist/index.mjs
CHANGED
|
@@ -4,6 +4,9 @@ import Cookie from 'js-cookie';
|
|
|
4
4
|
import QuickLRU from 'quick-lru';
|
|
5
5
|
import isEmpty from 'lodash/isEmpty';
|
|
6
6
|
import axios from 'axios';
|
|
7
|
+
import Keyv from 'keyv';
|
|
8
|
+
import { KeyvLocalStorage } from 'keyv-browser';
|
|
9
|
+
import isNumber from 'lodash/isNumber';
|
|
7
10
|
import omit from 'lodash/omit';
|
|
8
11
|
import isObject from 'lodash/isObject';
|
|
9
12
|
import stableStringify from 'json-stable-stringify';
|
|
@@ -475,7 +478,33 @@ const verifyResponse = async (response, onInvalid) => {
|
|
|
475
478
|
function getCSRFToken() {
|
|
476
479
|
return Cookie.get("x-csrf-token");
|
|
477
480
|
}
|
|
481
|
+
function getLoginToken() {
|
|
482
|
+
return Cookie.get("login_token");
|
|
483
|
+
}
|
|
484
|
+
async function getCSRFTokenByLoginToken() {
|
|
485
|
+
const csrfToken = getCSRFToken();
|
|
486
|
+
try {
|
|
487
|
+
const url = joinURL(window.location.origin, WELLKNOWN_SERVICE_PATH_PREFIX, "/api/did/csrfToken");
|
|
488
|
+
const { data } = await axios.get(url, {
|
|
489
|
+
headers: {
|
|
490
|
+
"x-csrf-token": csrfToken
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
return data;
|
|
494
|
+
} catch (error) {
|
|
495
|
+
console.error(error);
|
|
496
|
+
return {
|
|
497
|
+
loginToken: getLoginToken(),
|
|
498
|
+
csrfToken: null
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
}
|
|
478
502
|
|
|
503
|
+
const cacheTtl = window?.blocklet?.settings?.session?.cacheTtl;
|
|
504
|
+
const csrfTokenCache = new Keyv({
|
|
505
|
+
store: new KeyvLocalStorage(),
|
|
506
|
+
ttl: isNumber(cacheTtl) ? cacheTtl * 1e3 : 1e3 * 60 * 60
|
|
507
|
+
});
|
|
479
508
|
async function sleepForLoading(config, lazyTime = 300) {
|
|
480
509
|
config.metaData.endTime = +/* @__PURE__ */ new Date();
|
|
481
510
|
const { startTime, endTime } = config.metaData;
|
|
@@ -518,11 +547,33 @@ const createAxios$1 = (options, requestParams) => {
|
|
|
518
547
|
);
|
|
519
548
|
}
|
|
520
549
|
instance.interceptors.request.use(
|
|
521
|
-
(config) => {
|
|
550
|
+
async (config) => {
|
|
522
551
|
const componentDid = requestParams?.componentDid ?? window.blocklet?.componentId?.split("/").pop();
|
|
523
552
|
config.baseURL = config.baseURL || componentService.getComponentMountPoint(componentDid);
|
|
524
553
|
config.timeout = config.timeout || 20 * 1e3;
|
|
525
|
-
|
|
554
|
+
const loginToken = getLoginToken();
|
|
555
|
+
const csrfToken = getCSRFToken();
|
|
556
|
+
if (loginToken && csrfToken) {
|
|
557
|
+
const loginTokenKey = loginToken.slice(-32);
|
|
558
|
+
const csrfTokenFromCache = await csrfTokenCache.get(loginTokenKey);
|
|
559
|
+
if (csrfTokenFromCache) {
|
|
560
|
+
config.headers["x-csrf-token"] = csrfTokenFromCache;
|
|
561
|
+
} else {
|
|
562
|
+
const { loginToken: newLoginToken, csrfToken: newCsrfToken } = await getCSRFTokenByLoginToken();
|
|
563
|
+
if (newCsrfToken) {
|
|
564
|
+
await csrfTokenCache.set(newLoginToken.slice(-32), newCsrfToken);
|
|
565
|
+
config.headers["x-csrf-token"] = newCsrfToken;
|
|
566
|
+
} else {
|
|
567
|
+
config.headers["x-csrf-token"] = csrfToken;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
if (config.headers["x-csrf-token"] && config.headers["x-csrf-token"] !== getCSRFToken()) {
|
|
571
|
+
Cookie.set("x-csrf-token", config.headers["x-csrf-token"], {
|
|
572
|
+
sameSite: "strict",
|
|
573
|
+
secure: true
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
}
|
|
526
577
|
const visitorId = getVisitorId();
|
|
527
578
|
if (![void 0, null].includes(visitorId)) {
|
|
528
579
|
config.headers["x-blocklet-visitor-id"] = visitorId;
|
|
@@ -847,4 +898,4 @@ const getBlockletSDK = /* @__PURE__ */ (() => {
|
|
|
847
898
|
};
|
|
848
899
|
})();
|
|
849
900
|
|
|
850
|
-
export { BlockletSDK, createAxios, createFetch, getBlockletSDK, getCSRFToken };
|
|
901
|
+
export { BlockletSDK, createAxios, createFetch, getBlockletSDK, getCSRFToken, getCSRFTokenByLoginToken, getLoginToken };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/js-sdk",
|
|
3
|
-
"version": "1.17.3-beta-
|
|
3
|
+
"version": "1.17.3-beta-20251126-121502-d0926972",
|
|
4
4
|
"main": "dist/index.mjs",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -36,14 +36,16 @@
|
|
|
36
36
|
"watch": "nodemon -w src -e ts -x 'npm run build'"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@abtnode/constant": "1.17.3-beta-
|
|
40
|
-
"@arcblock/did": "^1.27.
|
|
41
|
-
"@blocklet/meta": "1.17.3-beta-
|
|
42
|
-
"@ocap/wallet": "^1.27.
|
|
39
|
+
"@abtnode/constant": "1.17.3-beta-20251126-121502-d0926972",
|
|
40
|
+
"@arcblock/did": "^1.27.12",
|
|
41
|
+
"@blocklet/meta": "1.17.3-beta-20251126-121502-d0926972",
|
|
42
|
+
"@ocap/wallet": "^1.27.12",
|
|
43
43
|
"axios": "^1.7.9",
|
|
44
44
|
"is-url": "^1.2.4",
|
|
45
45
|
"js-cookie": "^3.0.5",
|
|
46
46
|
"json-stable-stringify": "^1.0.1",
|
|
47
|
+
"keyv": "^4.5.4",
|
|
48
|
+
"keyv-browser": "^0.1.1",
|
|
47
49
|
"lodash": "^4.17.21",
|
|
48
50
|
"quick-lru": "^7.0.0",
|
|
49
51
|
"ufo": "^1.5.3"
|
|
@@ -62,5 +64,5 @@
|
|
|
62
64
|
"typescript": "^5.6.3",
|
|
63
65
|
"unbuild": "^2.0.0"
|
|
64
66
|
},
|
|
65
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "7039cacaad2a14a9573371e24e57cbbd6b6525c8"
|
|
66
68
|
}
|