@blocklet/js-sdk 1.16.32-beta-17be26d7 → 1.16.32-beta-f35ca4b8
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 +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +64 -16
- package/package.json +10 -6
package/dist/index.d.mts
CHANGED
|
@@ -75,6 +75,7 @@ declare class TokenService {
|
|
|
75
75
|
type RequestParams = {
|
|
76
76
|
lazy?: boolean;
|
|
77
77
|
lazyTime?: number;
|
|
78
|
+
componentDid?: string;
|
|
78
79
|
};
|
|
79
80
|
type BlockletComponent = TComponentInternalInfo;
|
|
80
81
|
type BlockletSettings = {
|
|
@@ -188,7 +189,7 @@ declare class UserSessionService {
|
|
|
188
189
|
declare class ComponentService {
|
|
189
190
|
private blocklet;
|
|
190
191
|
constructor({ blocklet }: {
|
|
191
|
-
blocklet
|
|
192
|
+
blocklet?: Blocklet;
|
|
192
193
|
});
|
|
193
194
|
getComponent(name: string): _blocklet_meta_lib_blocklet.TComponentInternalInfo;
|
|
194
195
|
getComponentMountPoint(name?: string): string;
|
package/dist/index.d.ts
CHANGED
|
@@ -75,6 +75,7 @@ declare class TokenService {
|
|
|
75
75
|
type RequestParams = {
|
|
76
76
|
lazy?: boolean;
|
|
77
77
|
lazyTime?: number;
|
|
78
|
+
componentDid?: string;
|
|
78
79
|
};
|
|
79
80
|
type BlockletComponent = TComponentInternalInfo;
|
|
80
81
|
type BlockletSettings = {
|
|
@@ -188,7 +189,7 @@ declare class UserSessionService {
|
|
|
188
189
|
declare class ComponentService {
|
|
189
190
|
private blocklet;
|
|
190
191
|
constructor({ blocklet }: {
|
|
191
|
-
blocklet
|
|
192
|
+
blocklet?: Blocklet;
|
|
192
193
|
});
|
|
193
194
|
getComponent(name: string): _blocklet_meta_lib_blocklet.TComponentInternalInfo;
|
|
194
195
|
getComponentMountPoint(name?: string): string;
|
package/dist/index.mjs
CHANGED
|
@@ -3,16 +3,17 @@ import { withQuery, joinURL } from 'ufo';
|
|
|
3
3
|
import Cookie from 'js-cookie';
|
|
4
4
|
import QuickLRU from 'quick-lru';
|
|
5
5
|
import axios from 'axios';
|
|
6
|
+
import isUrl from 'is-url';
|
|
6
7
|
|
|
7
|
-
var __defProp$
|
|
8
|
-
var __defNormalProp$
|
|
9
|
-
var __publicField$
|
|
10
|
-
__defNormalProp$
|
|
8
|
+
var __defProp$3 = Object.defineProperty;
|
|
9
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __publicField$3 = (obj, key, value) => {
|
|
11
|
+
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
11
12
|
return value;
|
|
12
13
|
};
|
|
13
14
|
class AuthService {
|
|
14
15
|
constructor({ api }) {
|
|
15
|
-
__publicField$
|
|
16
|
+
__publicField$3(this, "api");
|
|
16
17
|
this.api = api;
|
|
17
18
|
}
|
|
18
19
|
async getUserPublicInfo({ did }) {
|
|
@@ -149,16 +150,16 @@ class BlockletService {
|
|
|
149
150
|
}
|
|
150
151
|
}
|
|
151
152
|
|
|
152
|
-
var __defProp$
|
|
153
|
-
var __defNormalProp$
|
|
154
|
-
var __publicField$
|
|
155
|
-
__defNormalProp$
|
|
153
|
+
var __defProp$2 = Object.defineProperty;
|
|
154
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
155
|
+
var __publicField$2 = (obj, key, value) => {
|
|
156
|
+
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
156
157
|
return value;
|
|
157
158
|
};
|
|
158
159
|
class UserSessionService {
|
|
159
160
|
constructor({ api, blocklet }) {
|
|
160
|
-
__publicField$
|
|
161
|
-
__publicField$
|
|
161
|
+
__publicField$2(this, "api");
|
|
162
|
+
__publicField$2(this, "blocklet");
|
|
162
163
|
this.api = api;
|
|
163
164
|
this.blocklet = blocklet || new BlockletService();
|
|
164
165
|
}
|
|
@@ -174,6 +175,33 @@ class UserSessionService {
|
|
|
174
175
|
}
|
|
175
176
|
}
|
|
176
177
|
|
|
178
|
+
var __defProp$1 = Object.defineProperty;
|
|
179
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
180
|
+
var __publicField$1 = (obj, key, value) => {
|
|
181
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
182
|
+
return value;
|
|
183
|
+
};
|
|
184
|
+
class ComponentService {
|
|
185
|
+
constructor({ blocklet = window.blocklet }) {
|
|
186
|
+
__publicField$1(this, "blocklet");
|
|
187
|
+
this.blocklet = blocklet;
|
|
188
|
+
}
|
|
189
|
+
getComponent(name) {
|
|
190
|
+
const componentMountPoints = this.blocklet?.componentMountPoints || [];
|
|
191
|
+
const item = componentMountPoints.find((x) => [x.title, x.name, x.did].includes(name));
|
|
192
|
+
return item;
|
|
193
|
+
}
|
|
194
|
+
getComponentMountPoint(name) {
|
|
195
|
+
const component = this.getComponent(name);
|
|
196
|
+
return component?.mountPoint || "";
|
|
197
|
+
}
|
|
198
|
+
getUrl(name, ...parts) {
|
|
199
|
+
const mountPoint = this.getComponentMountPoint(name);
|
|
200
|
+
const appUrl = this.blocklet?.appUrl || "";
|
|
201
|
+
return joinURL(appUrl, mountPoint, ...parts);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
177
205
|
const version = "1.16.31";
|
|
178
206
|
|
|
179
207
|
const sleep = (time = 0) => {
|
|
@@ -191,6 +219,10 @@ const getVisitorId = () => {
|
|
|
191
219
|
return localStorage.getItem(visitorIdKey);
|
|
192
220
|
};
|
|
193
221
|
|
|
222
|
+
function getCSRFToken() {
|
|
223
|
+
return Cookie.get("x-csrf-token");
|
|
224
|
+
}
|
|
225
|
+
|
|
194
226
|
async function sleepForLoading(config, lazyTime = 300) {
|
|
195
227
|
config.metaData.endTime = +/* @__PURE__ */ new Date();
|
|
196
228
|
const { startTime, endTime } = config.metaData;
|
|
@@ -231,6 +263,16 @@ const createAxios$1 = (options, requestParams) => {
|
|
|
231
263
|
}
|
|
232
264
|
);
|
|
233
265
|
}
|
|
266
|
+
instance.interceptors.request.use(
|
|
267
|
+
(config) => {
|
|
268
|
+
const componentDid = requestParams?.componentDid ?? window.blocklet?.componentId?.split("/").pop();
|
|
269
|
+
config.baseURL = new ComponentService({}).getComponentMountPoint(componentDid);
|
|
270
|
+
config.headers["x-csrf-token"] = getCSRFToken();
|
|
271
|
+
config.timeout = 20 * 1e3;
|
|
272
|
+
return config;
|
|
273
|
+
},
|
|
274
|
+
(error) => Promise.reject(error)
|
|
275
|
+
);
|
|
234
276
|
return instance;
|
|
235
277
|
};
|
|
236
278
|
async function renewRefreshToken$1(refreshToken) {
|
|
@@ -321,6 +363,7 @@ function createFetch$1(globalOptions = {}, requestParams) {
|
|
|
321
363
|
const headers = {
|
|
322
364
|
...globalOptions?.headers,
|
|
323
365
|
...options?.headers,
|
|
366
|
+
"x-csrf-token": getCSRFToken(),
|
|
324
367
|
"x-blocklet-js-sdk-version": version
|
|
325
368
|
};
|
|
326
369
|
const visitorId = getVisitorId();
|
|
@@ -376,7 +419,16 @@ function createRequest({
|
|
|
376
419
|
const service = createFetch$1(requestOptions, requestParams);
|
|
377
420
|
return async (input, options) => {
|
|
378
421
|
let authorization;
|
|
379
|
-
|
|
422
|
+
let finalUrl = input;
|
|
423
|
+
if (typeof input === "string") {
|
|
424
|
+
if (baseURL) {
|
|
425
|
+
finalUrl = joinURL(baseURL, input);
|
|
426
|
+
} else if (!isUrl(input)) {
|
|
427
|
+
const componentDid = requestParams?.componentDid ?? window.blocklet?.componentId?.split("/").pop();
|
|
428
|
+
const mountPoint = new ComponentService({}).getComponentMountPoint(componentDid);
|
|
429
|
+
finalUrl = joinURL(mountPoint, input);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
380
432
|
if (!Cookie.get(SESSION_TOKEN_STORAGE_KEY)) {
|
|
381
433
|
const token = getSessionToken();
|
|
382
434
|
if (token) {
|
|
@@ -466,10 +518,6 @@ class BlockletSDK {
|
|
|
466
518
|
}
|
|
467
519
|
function createAxios(config = {}, requestParams = {}) {
|
|
468
520
|
const tokenService = new TokenService();
|
|
469
|
-
const blockletService = new BlockletService();
|
|
470
|
-
if (config.baseURL === void 0) {
|
|
471
|
-
config.baseURL = blockletService.getPrefix();
|
|
472
|
-
}
|
|
473
521
|
return createRequest$1(
|
|
474
522
|
{
|
|
475
523
|
getSessionToken: tokenService.getSessionToken,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/js-sdk",
|
|
3
|
-
"version": "1.16.32-beta-
|
|
3
|
+
"version": "1.16.32-beta-f35ca4b8",
|
|
4
4
|
"main": "dist/index.mjs",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -28,18 +28,22 @@
|
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
30
30
|
"build:blocklet-js-sdk": "npm run build",
|
|
31
|
-
"build": "unbuild"
|
|
31
|
+
"build": "unbuild",
|
|
32
|
+
"watch": "nodemon -w src -e ts -x 'npm run build'"
|
|
32
33
|
},
|
|
33
34
|
"dependencies": {
|
|
34
|
-
"@abtnode/constant": "1.16.32-beta-
|
|
35
|
-
"@blocklet/meta": "1.16.32-beta-
|
|
35
|
+
"@abtnode/constant": "1.16.32-beta-f35ca4b8",
|
|
36
|
+
"@blocklet/meta": "1.16.32-beta-f35ca4b8",
|
|
36
37
|
"axios": "^1.7.5",
|
|
38
|
+
"is-url": "^1.2.4",
|
|
37
39
|
"js-cookie": "^3.0.5",
|
|
38
40
|
"quick-lru": "^7.0.0",
|
|
39
41
|
"ufo": "^1.5.3"
|
|
40
42
|
},
|
|
41
43
|
"devDependencies": {
|
|
42
|
-
"
|
|
44
|
+
"@types/is-url": "^1.2.32",
|
|
45
|
+
"unbuild": "^2.0.0",
|
|
46
|
+
"vitest": "^2.0.5"
|
|
43
47
|
},
|
|
44
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "061103ce2e5a200eb4c318b41ccb7ea92b6c4ca3"
|
|
45
49
|
}
|