@blocklet/js-sdk 1.16.33-beta-20241024-064549-2c1ad302 → 1.16.33-beta-20241028-164124-17cf3c21
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 +13 -2
- package/dist/index.d.ts +13 -2
- package/dist/index.mjs +66 -26
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -112,6 +112,7 @@ type Blocklet = {
|
|
|
112
112
|
appLogo: string;
|
|
113
113
|
appLogoRect: string;
|
|
114
114
|
appUrl: string;
|
|
115
|
+
domainAliases?: string[];
|
|
115
116
|
isComponent: boolean;
|
|
116
117
|
prefix: string;
|
|
117
118
|
groupPrefix: string;
|
|
@@ -181,8 +182,17 @@ declare class UserSessionService {
|
|
|
181
182
|
api: Axios;
|
|
182
183
|
blocklet?: BlockletService;
|
|
183
184
|
});
|
|
184
|
-
|
|
185
|
+
getBaseUrl(appUrl?: string): string | undefined;
|
|
186
|
+
getUserSessions({ did, appUrl }: {
|
|
185
187
|
did: string;
|
|
188
|
+
appUrl?: string;
|
|
189
|
+
}): Promise<UserSession[]>;
|
|
190
|
+
loginByUserSession({ appPid, userDid, visitorId, passportId, appUrl, }: {
|
|
191
|
+
appPid: string;
|
|
192
|
+
userDid: string;
|
|
193
|
+
visitorId: string;
|
|
194
|
+
passportId: string;
|
|
195
|
+
appUrl?: string;
|
|
186
196
|
}): Promise<UserSession[]>;
|
|
187
197
|
}
|
|
188
198
|
|
|
@@ -208,5 +218,6 @@ declare class BlockletSDK {
|
|
|
208
218
|
}
|
|
209
219
|
declare function createAxios(config?: AxiosRequestConfig, requestParams?: RequestParams): axios.AxiosInstance;
|
|
210
220
|
declare function createFetch(options?: RequestInit, requestParams?: RequestParams): (input: string | Request | URL, options?: RequestInit) => Promise<Response>;
|
|
221
|
+
declare const getBlockletSDK: () => BlockletSDK;
|
|
211
222
|
|
|
212
|
-
export { AuthService, BlockletSDK, BlockletService, ComponentService, type NotificationConfig, type PrivacyConfig, TokenService, type UserPublicInfo, type UserSession, UserSessionService, type UserSessionUser, type Webhook, createAxios, createFetch, getCSRFToken };
|
|
223
|
+
export { AuthService, BlockletSDK, BlockletService, ComponentService, type NotificationConfig, type PrivacyConfig, TokenService, type UserPublicInfo, type UserSession, UserSessionService, type UserSessionUser, type Webhook, createAxios, createFetch, getBlockletSDK, getCSRFToken };
|
package/dist/index.d.ts
CHANGED
|
@@ -112,6 +112,7 @@ type Blocklet = {
|
|
|
112
112
|
appLogo: string;
|
|
113
113
|
appLogoRect: string;
|
|
114
114
|
appUrl: string;
|
|
115
|
+
domainAliases?: string[];
|
|
115
116
|
isComponent: boolean;
|
|
116
117
|
prefix: string;
|
|
117
118
|
groupPrefix: string;
|
|
@@ -181,8 +182,17 @@ declare class UserSessionService {
|
|
|
181
182
|
api: Axios;
|
|
182
183
|
blocklet?: BlockletService;
|
|
183
184
|
});
|
|
184
|
-
|
|
185
|
+
getBaseUrl(appUrl?: string): string | undefined;
|
|
186
|
+
getUserSessions({ did, appUrl }: {
|
|
185
187
|
did: string;
|
|
188
|
+
appUrl?: string;
|
|
189
|
+
}): Promise<UserSession[]>;
|
|
190
|
+
loginByUserSession({ appPid, userDid, visitorId, passportId, appUrl, }: {
|
|
191
|
+
appPid: string;
|
|
192
|
+
userDid: string;
|
|
193
|
+
visitorId: string;
|
|
194
|
+
passportId: string;
|
|
195
|
+
appUrl?: string;
|
|
186
196
|
}): Promise<UserSession[]>;
|
|
187
197
|
}
|
|
188
198
|
|
|
@@ -208,5 +218,6 @@ declare class BlockletSDK {
|
|
|
208
218
|
}
|
|
209
219
|
declare function createAxios(config?: AxiosRequestConfig, requestParams?: RequestParams): axios.AxiosInstance;
|
|
210
220
|
declare function createFetch(options?: RequestInit, requestParams?: RequestParams): (input: string | Request | URL, options?: RequestInit) => Promise<Response>;
|
|
221
|
+
declare const getBlockletSDK: () => BlockletSDK;
|
|
211
222
|
|
|
212
|
-
export { AuthService, BlockletSDK, BlockletService, ComponentService, type NotificationConfig, type PrivacyConfig, TokenService, type UserPublicInfo, type UserSession, UserSessionService, type UserSessionUser, type Webhook, createAxios, createFetch, getCSRFToken };
|
|
223
|
+
export { AuthService, BlockletSDK, BlockletService, ComponentService, type NotificationConfig, type PrivacyConfig, TokenService, type UserPublicInfo, type UserSession, UserSessionService, type UserSessionUser, type Webhook, createAxios, createFetch, getBlockletSDK, getCSRFToken };
|
package/dist/index.mjs
CHANGED
|
@@ -163,9 +163,14 @@ class UserSessionService {
|
|
|
163
163
|
this.api = api;
|
|
164
164
|
this.blocklet = blocklet || new BlockletService();
|
|
165
165
|
}
|
|
166
|
-
|
|
166
|
+
getBaseUrl(appUrl) {
|
|
167
|
+
return appUrl ? joinURL(appUrl, WELLKNOWN_SERVICE_PATH_PREFIX) : void 0;
|
|
168
|
+
}
|
|
169
|
+
async getUserSessions({ did, appUrl }) {
|
|
170
|
+
const baseURL = this.getBaseUrl(appUrl);
|
|
167
171
|
const blocklet = await this.blocklet.getBlocklet();
|
|
168
172
|
const { data } = await this.api.get("/api/user-session", {
|
|
173
|
+
baseURL,
|
|
169
174
|
params: {
|
|
170
175
|
userDid: did,
|
|
171
176
|
appPid: blocklet.appPid
|
|
@@ -173,6 +178,26 @@ class UserSessionService {
|
|
|
173
178
|
});
|
|
174
179
|
return data;
|
|
175
180
|
}
|
|
181
|
+
async loginByUserSession({
|
|
182
|
+
appPid,
|
|
183
|
+
userDid,
|
|
184
|
+
visitorId,
|
|
185
|
+
passportId,
|
|
186
|
+
appUrl
|
|
187
|
+
}) {
|
|
188
|
+
const baseURL = this.getBaseUrl(appUrl);
|
|
189
|
+
const { data } = await this.api.post(
|
|
190
|
+
"/api/user-session/login",
|
|
191
|
+
{
|
|
192
|
+
appPid,
|
|
193
|
+
userDid,
|
|
194
|
+
visitorId,
|
|
195
|
+
passportId
|
|
196
|
+
},
|
|
197
|
+
{ baseURL }
|
|
198
|
+
);
|
|
199
|
+
return data;
|
|
200
|
+
}
|
|
176
201
|
}
|
|
177
202
|
|
|
178
203
|
var __defProp$1 = Object.defineProperty;
|
|
@@ -255,11 +280,15 @@ const createAxios$1 = (options, requestParams) => {
|
|
|
255
280
|
);
|
|
256
281
|
instance.interceptors.response.use(
|
|
257
282
|
async (res) => {
|
|
258
|
-
|
|
283
|
+
if (res.config) {
|
|
284
|
+
await sleepForLoading(res.config, requestParams?.lazyTime);
|
|
285
|
+
}
|
|
259
286
|
return res;
|
|
260
287
|
},
|
|
261
288
|
async (err) => {
|
|
262
|
-
|
|
289
|
+
if (err.response) {
|
|
290
|
+
await sleepForLoading(err.response.config, requestParams?.lazyTime);
|
|
291
|
+
}
|
|
263
292
|
return Promise.reject(err);
|
|
264
293
|
}
|
|
265
294
|
);
|
|
@@ -327,29 +356,31 @@ function createRequest$1({
|
|
|
327
356
|
(response) => response,
|
|
328
357
|
async (error) => {
|
|
329
358
|
const originalRequest = error.config;
|
|
330
|
-
originalRequest
|
|
331
|
-
|
|
332
|
-
originalRequest._retry
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
onRefreshTokenSuccess
|
|
359
|
+
if (originalRequest) {
|
|
360
|
+
originalRequest.headers = originalRequest?.headers ? { ...originalRequest.headers } : {};
|
|
361
|
+
if (error?.response?.status === 401 && !originalRequest._retry) {
|
|
362
|
+
originalRequest._retry = true;
|
|
363
|
+
try {
|
|
364
|
+
if (!refreshingTokenRequest) {
|
|
365
|
+
refreshingTokenRequest = renewRefreshToken$1(getRefreshToken());
|
|
366
|
+
}
|
|
367
|
+
const tokenData = await refreshingTokenRequest;
|
|
368
|
+
setSessionToken(tokenData.nextToken);
|
|
369
|
+
setRefreshToken(tokenData.nextRefreshToken);
|
|
370
|
+
if (typeof onRefreshTokenSuccess === "function") {
|
|
371
|
+
onRefreshTokenSuccess(tokenData);
|
|
372
|
+
}
|
|
373
|
+
return service(originalRequest);
|
|
374
|
+
} catch (refreshTokenError) {
|
|
375
|
+
removeSessionToken();
|
|
376
|
+
removeRefreshToken();
|
|
377
|
+
if (typeof onRefreshTokenError === "function") {
|
|
378
|
+
onRefreshTokenError(refreshTokenError);
|
|
379
|
+
}
|
|
380
|
+
return Promise.reject(error);
|
|
381
|
+
} finally {
|
|
382
|
+
refreshingTokenRequest = null;
|
|
342
383
|
}
|
|
343
|
-
return service(originalRequest);
|
|
344
|
-
} catch (refreshTokenError) {
|
|
345
|
-
removeSessionToken();
|
|
346
|
-
removeRefreshToken();
|
|
347
|
-
if (typeof onRefreshTokenError === "function") {
|
|
348
|
-
onRefreshTokenError(refreshTokenError);
|
|
349
|
-
}
|
|
350
|
-
return Promise.reject(error);
|
|
351
|
-
} finally {
|
|
352
|
-
refreshingTokenRequest = null;
|
|
353
384
|
}
|
|
354
385
|
}
|
|
355
386
|
return Promise.reject(error);
|
|
@@ -560,5 +591,14 @@ function createFetch(options, requestParams) {
|
|
|
560
591
|
requestParams
|
|
561
592
|
);
|
|
562
593
|
}
|
|
594
|
+
const getBlockletSDK = /* @__PURE__ */ (() => {
|
|
595
|
+
let instance;
|
|
596
|
+
return () => {
|
|
597
|
+
if (!instance) {
|
|
598
|
+
instance = new BlockletSDK();
|
|
599
|
+
}
|
|
600
|
+
return instance;
|
|
601
|
+
};
|
|
602
|
+
})();
|
|
563
603
|
|
|
564
|
-
export { BlockletSDK, createAxios, createFetch, getCSRFToken };
|
|
604
|
+
export { BlockletSDK, createAxios, createFetch, getBlockletSDK, getCSRFToken };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/js-sdk",
|
|
3
|
-
"version": "1.16.33-beta-
|
|
3
|
+
"version": "1.16.33-beta-20241028-164124-17cf3c21",
|
|
4
4
|
"main": "dist/index.mjs",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"watch": "nodemon -w src -e ts -x 'npm run build'"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@abtnode/constant": "1.16.33-beta-
|
|
36
|
-
"@blocklet/meta": "1.16.33-beta-
|
|
35
|
+
"@abtnode/constant": "1.16.33-beta-20241028-164124-17cf3c21",
|
|
36
|
+
"@blocklet/meta": "1.16.33-beta-20241028-164124-17cf3c21",
|
|
37
37
|
"axios": "^1.7.5",
|
|
38
38
|
"is-url": "^1.2.4",
|
|
39
39
|
"js-cookie": "^3.0.5",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"unbuild": "^2.0.0",
|
|
46
46
|
"vitest": "^2.0.5"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "df5cccba1192375274247a8770fe07f9dc248994"
|
|
49
49
|
}
|