@blocklet/js-sdk 1.16.32-beta-5463e017 → 1.16.32-beta-93e1a798
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 +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.mjs +68 -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 = {
|
|
@@ -187,8 +188,8 @@ declare class UserSessionService {
|
|
|
187
188
|
|
|
188
189
|
declare class ComponentService {
|
|
189
190
|
private blocklet;
|
|
190
|
-
constructor({ blocklet }
|
|
191
|
-
blocklet
|
|
191
|
+
constructor({ 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 = {
|
|
@@ -187,8 +188,8 @@ declare class UserSessionService {
|
|
|
187
188
|
|
|
188
189
|
declare class ComponentService {
|
|
189
190
|
private blocklet;
|
|
190
|
-
constructor({ blocklet }
|
|
191
|
-
blocklet
|
|
191
|
+
constructor({ 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;
|
|
@@ -204,6 +236,7 @@ const createAxios$1 = (options, requestParams) => {
|
|
|
204
236
|
...options?.headers,
|
|
205
237
|
"x-blocklet-js-sdk-version": version
|
|
206
238
|
};
|
|
239
|
+
const componentService = new ComponentService();
|
|
207
240
|
const visitorId = getVisitorId();
|
|
208
241
|
if (![void 0, null].includes(visitorId)) {
|
|
209
242
|
headers["x-blocklet-visitor-id"] = visitorId;
|
|
@@ -231,6 +264,16 @@ const createAxios$1 = (options, requestParams) => {
|
|
|
231
264
|
}
|
|
232
265
|
);
|
|
233
266
|
}
|
|
267
|
+
instance.interceptors.request.use(
|
|
268
|
+
(config) => {
|
|
269
|
+
const componentDid = requestParams?.componentDid ?? window.blocklet?.componentId?.split("/").pop();
|
|
270
|
+
config.baseURL = config.baseURL || componentService.getComponentMountPoint(componentDid);
|
|
271
|
+
config.timeout = config.timeout || 20 * 1e3;
|
|
272
|
+
config.headers["x-csrf-token"] = getCSRFToken();
|
|
273
|
+
return config;
|
|
274
|
+
},
|
|
275
|
+
(error) => Promise.reject(error)
|
|
276
|
+
);
|
|
234
277
|
return instance;
|
|
235
278
|
};
|
|
236
279
|
async function renewRefreshToken$1(refreshToken) {
|
|
@@ -321,6 +364,7 @@ function createFetch$1(globalOptions = {}, requestParams) {
|
|
|
321
364
|
const headers = {
|
|
322
365
|
...globalOptions?.headers,
|
|
323
366
|
...options?.headers,
|
|
367
|
+
"x-csrf-token": getCSRFToken(),
|
|
324
368
|
"x-blocklet-js-sdk-version": version
|
|
325
369
|
};
|
|
326
370
|
const visitorId = getVisitorId();
|
|
@@ -374,9 +418,21 @@ function createRequest({
|
|
|
374
418
|
}, requestOptions, requestParams) {
|
|
375
419
|
let refreshingTokenRequest = null;
|
|
376
420
|
const service = createFetch$1(requestOptions, requestParams);
|
|
421
|
+
const componentService = new ComponentService();
|
|
377
422
|
return async (input, options) => {
|
|
378
423
|
let authorization;
|
|
379
|
-
|
|
424
|
+
let finalUrl = input;
|
|
425
|
+
if (typeof input === "string") {
|
|
426
|
+
if (!isUrl(input)) {
|
|
427
|
+
if (baseURL) {
|
|
428
|
+
finalUrl = joinURL(baseURL, input);
|
|
429
|
+
} else {
|
|
430
|
+
const componentDid = requestParams?.componentDid ?? window.blocklet?.componentId?.split("/").pop();
|
|
431
|
+
const mountPoint = componentService.getComponentMountPoint(componentDid);
|
|
432
|
+
finalUrl = joinURL(mountPoint, input);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
380
436
|
if (!Cookie.get(SESSION_TOKEN_STORAGE_KEY)) {
|
|
381
437
|
const token = getSessionToken();
|
|
382
438
|
if (token) {
|
|
@@ -466,10 +522,6 @@ class BlockletSDK {
|
|
|
466
522
|
}
|
|
467
523
|
function createAxios(config = {}, requestParams = {}) {
|
|
468
524
|
const tokenService = new TokenService();
|
|
469
|
-
const blockletService = new BlockletService();
|
|
470
|
-
if (config.baseURL === void 0) {
|
|
471
|
-
config.baseURL = blockletService.getPrefix();
|
|
472
|
-
}
|
|
473
525
|
return createRequest$1(
|
|
474
526
|
{
|
|
475
527
|
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-93e1a798",
|
|
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-93e1a798",
|
|
36
|
+
"@blocklet/meta": "1.16.32-beta-93e1a798",
|
|
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": "608fab914e6ee5cb5659c11ab3d0713945ab99a0"
|
|
45
49
|
}
|