@lark-apaas/dataloom 0.1.4-alpha.2 → 0.1.4-alpha.4
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/README.md +24 -32
- package/lib/DataloomClient.d.ts +7 -7
- package/lib/DataloomClient.d.ts.map +1 -1
- package/lib/DataloomClient.js +6 -15
- package/lib/index.d.ts +5 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/service/index.d.ts +26 -5
- package/lib/service/index.d.ts.map +1 -1
- package/lib/service/index.js +3 -6
- package/lib/service/types.d.ts +113 -0
- package/lib/service/types.d.ts.map +1 -0
- package/lib/storage/StorageClient.d.ts +1 -3
- package/lib/storage/StorageClient.d.ts.map +1 -1
- package/lib/storage/StorageClient.js +6 -4
- package/lib/storage/libs/fetch.d.ts +6 -0
- package/lib/storage/libs/fetch.d.ts.map +1 -1
- package/lib/storage/libs/fetch.js +11 -1
- package/lib/storage/libs/helpers.d.ts +14 -0
- package/lib/storage/libs/helpers.d.ts.map +1 -1
- package/lib/storage/libs/helpers.js +6 -1
- package/lib/storage/libs/types.d.ts +5 -6
- package/lib/storage/libs/types.d.ts.map +1 -1
- package/lib/storage/packages/StorageFileApi.d.ts.map +1 -1
- package/lib/storage/packages/StorageFileApi.js +14 -14
- package/lib/storage/utils/csrf.d.ts +11 -0
- package/lib/storage/utils/csrf.d.ts.map +1 -0
- package/lib/storage/utils/csrf.js +10 -0
- package/lib/utils/fetch.d.ts +8 -1
- package/lib/utils/fetch.d.ts.map +1 -1
- package/lib/utils/fetch.js +3 -8
- package/lib/utils/helpers.d.ts +0 -1
- package/lib/utils/helpers.d.ts.map +1 -1
- package/lib/utils/helpers.js +1 -4
- package/lib/utils/types.d.ts +10 -0
- package/lib/utils/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/lib/service/services/DataloomServiceBase.d.ts +0 -17
- package/lib/service/services/DataloomServiceBase.d.ts.map +0 -1
- package/lib/service/services/DataloomServiceBase.js +0 -126
- package/lib/service/services/session-service/index.d.ts +0 -45
- package/lib/service/services/session-service/index.d.ts.map +0 -1
- package/lib/service/services/session-service/index.js +0 -137
- package/lib/service/services/session-service/types.d.ts +0 -34
- package/lib/service/services/session-service/types.d.ts.map +0 -1
- package/lib/service/services/types.d.ts +0 -12
- package/lib/service/services/types.d.ts.map +0 -1
- package/lib/service/services/types.js +0 -14
- package/lib/service/services/user-service/index.d.ts +0 -9
- package/lib/service/services/user-service/index.d.ts.map +0 -1
- package/lib/service/services/user-service/index.js +0 -62
- package/lib/service/services/user-service/types.d.ts +0 -57
- package/lib/service/services/user-service/types.d.ts.map +0 -1
- package/lib/service/services/user-service/types.js +0 -0
- package/lib/service/utils/helpers.d.ts +0 -8
- package/lib/service/utils/helpers.d.ts.map +0 -1
- package/lib/service/utils/helpers.js +0 -18
- package/lib/service/utils/logger.d.ts +0 -15
- package/lib/service/utils/logger.d.ts.map +0 -1
- package/lib/service/utils/logger.js +0 -18
- package/lib/service/utils/trace-id.d.ts +0 -45
- package/lib/service/utils/trace-id.d.ts.map +0 -1
- package/lib/service/utils/trace-id.js +0 -20
- package/lib/service/utils/types.d.ts +0 -49
- package/lib/service/utils/types.d.ts.map +0 -1
- package/lib/service/utils/types.js +0 -7
- /package/lib/service/{services/session-service/types.js → types.js} +0 -0
|
@@ -33,12 +33,12 @@ class StorageFileApi {
|
|
|
33
33
|
if (options?.contentDisposition) contentDisposition = options?.contentDisposition;
|
|
34
34
|
else if (fileBody instanceof File) contentDisposition = fileBody?.name;
|
|
35
35
|
const preUploadBody = {
|
|
36
|
-
|
|
37
|
-
file_size: getUpdateFileSize(fileBody),
|
|
36
|
+
fileSize: getUpdateFileSize(fileBody),
|
|
38
37
|
upsert: options.upsert ?? false,
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
filePath: cleanPath,
|
|
39
|
+
fileName: fileBody instanceof File ? fileBody?.name : ''
|
|
41
40
|
};
|
|
41
|
+
if (options.contentType) preUploadBody.contentType = options.contentType;
|
|
42
42
|
const res = await post(this.fetch, `${this.url}/object/${this.bucketId}/pre_upload`, preUploadBody, {
|
|
43
43
|
headers: this.headers,
|
|
44
44
|
logFetch: this.loggerEnabled,
|
|
@@ -46,18 +46,19 @@ class StorageFileApi {
|
|
|
46
46
|
}, void 0, {
|
|
47
47
|
psmName: 'Storage.Upload.PreUpload'
|
|
48
48
|
});
|
|
49
|
-
const {
|
|
50
|
-
if (!
|
|
49
|
+
const { uploadID, uploadUrl } = res?.data ?? {};
|
|
50
|
+
if (!uploadUrl || !uploadID) return {
|
|
51
51
|
data: null,
|
|
52
|
-
error: new StorageError('
|
|
52
|
+
error: new StorageError('uploadURL or uploadID is empty')
|
|
53
53
|
};
|
|
54
54
|
{
|
|
55
55
|
const tosHeaders = {};
|
|
56
56
|
if (contentDisposition) tosHeaders['content-disposition'] = `attachment; filename="${sanitizeFileName(contentDisposition)}"`;
|
|
57
57
|
if (options.cacheControl || 0 === options.cacheControl) tosHeaders['cache-control'] = `max-age=${options.cacheControl}`;
|
|
58
58
|
if (options.contentType) tosHeaders['content-type'] = options.contentType;
|
|
59
|
-
const tosRes = await put(this.fetch,
|
|
59
|
+
const tosRes = await put(this.fetch, uploadUrl, fileBody, {
|
|
60
60
|
noResolveJson: true,
|
|
61
|
+
noCredentials: true,
|
|
61
62
|
headers: tosHeaders,
|
|
62
63
|
logFetch: this.loggerEnabled,
|
|
63
64
|
onRequestError: this.onRequestError
|
|
@@ -66,9 +67,8 @@ class StorageFileApi {
|
|
|
66
67
|
});
|
|
67
68
|
const etag = tosRes?.headers?.get('Etag') ?? '';
|
|
68
69
|
const callbackRes = await post(this.fetch, `${this.url}/object/callback`, {
|
|
69
|
-
|
|
70
|
-
etag
|
|
71
|
-
app_id: this.appId
|
|
70
|
+
uploadID,
|
|
71
|
+
eTag: etag
|
|
72
72
|
}, {
|
|
73
73
|
headers: this.headers,
|
|
74
74
|
logFetch: this.loggerEnabled,
|
|
@@ -113,7 +113,7 @@ class StorageFileApi {
|
|
|
113
113
|
try {
|
|
114
114
|
const _path = this._getFinalPath(path);
|
|
115
115
|
const res = await post(this.fetch, `${this.url}/object/sign/${_path}`, {
|
|
116
|
-
|
|
116
|
+
expiresIn: toValidExpiresIn(expiresIn)
|
|
117
117
|
}, {
|
|
118
118
|
headers: this.headers,
|
|
119
119
|
logFetch: this.loggerEnabled,
|
|
@@ -140,7 +140,7 @@ class StorageFileApi {
|
|
|
140
140
|
try {
|
|
141
141
|
const _paths = paths.map((path)=>this._retrieveFilePathFromDownloadUrl(path));
|
|
142
142
|
const res = await post(this.fetch, `${this.url}/object/sign/${this.bucketId}`, {
|
|
143
|
-
|
|
143
|
+
expiresIn: toValidExpiresIn(expiresIn),
|
|
144
144
|
paths: _paths
|
|
145
145
|
}, {
|
|
146
146
|
headers: this.headers,
|
|
@@ -359,7 +359,7 @@ class StorageFileApi {
|
|
|
359
359
|
return '';
|
|
360
360
|
}
|
|
361
361
|
async _copyWithinVolcEngine(url) {
|
|
362
|
-
const res = await post(this.fetch, `${this.url}/
|
|
362
|
+
const res = await post(this.fetch, `${this.url}/object/${this.bucketId}/copy`, {
|
|
363
363
|
source: {
|
|
364
364
|
type: 'externalTOS',
|
|
365
365
|
externalURL: url
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 获取cookie中存放的suda-csrf-token值
|
|
3
|
+
* @returns {string | null} - suda-csrf-token的值,如果不存在则返回null
|
|
4
|
+
*/
|
|
5
|
+
export declare function getCsrfToken(): string | null;
|
|
6
|
+
declare global {
|
|
7
|
+
interface Window {
|
|
8
|
+
csrfToken?: string;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=csrf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csrf.d.ts","sourceRoot":"","sources":["../../../src/storage/utils/csrf.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,YAAY,kBAiB3B;AAID,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB;CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
function getCsrfToken() {
|
|
2
|
+
const cookieName = 'suda-csrf-token';
|
|
3
|
+
const cookies = document.cookie.split('; ');
|
|
4
|
+
for (const cookie of cookies){
|
|
5
|
+
const [name, value] = cookie.split('=');
|
|
6
|
+
if (name === cookieName) return decodeURIComponent(value);
|
|
7
|
+
}
|
|
8
|
+
return window.csrfToken ?? null;
|
|
9
|
+
}
|
|
10
|
+
export { getCsrfToken };
|
package/lib/utils/fetch.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import type RateLimiter from '../RateLimiter';
|
|
2
2
|
import type { Fetch } from './types';
|
|
3
3
|
export declare const resolveFetch: (customFetch?: Fetch) => Fetch;
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Wrap a fetch implementation with client-side rate limiting.
|
|
6
|
+
*
|
|
7
|
+
* Storage now relies on cookie session authentication (`credentials: 'include'`
|
|
8
|
+
* is added at the storage request layer), so no `apikey` header is injected
|
|
9
|
+
* here any more.
|
|
10
|
+
*/
|
|
11
|
+
export declare const createRateLimitedFetch: (rateLimiter?: RateLimiter, customFetch?: Fetch) => Fetch;
|
|
5
12
|
//# sourceMappingURL=fetch.d.ts.map
|
package/lib/utils/fetch.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/utils/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC,eAAO,MAAM,YAAY,GAAI,cAAc,KAAK,KAAG,KAQlD,CAAC;AAEF,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/utils/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC,eAAO,MAAM,YAAY,GAAI,cAAc,KAAK,KAAG,KAQlD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,GACjC,cAAc,WAAW,EACzB,cAAc,KAAK,KAClB,KAeF,CAAC"}
|
package/lib/utils/fetch.js
CHANGED
|
@@ -3,19 +3,14 @@ const resolveFetch = (customFetch)=>{
|
|
|
3
3
|
_fetch = customFetch ? customFetch : fetch;
|
|
4
4
|
return (input, init)=>_fetch(input, init);
|
|
5
5
|
};
|
|
6
|
-
const
|
|
6
|
+
const createRateLimitedFetch = (rateLimiter, customFetch)=>{
|
|
7
7
|
const resolvedFetch = resolveFetch(customFetch);
|
|
8
8
|
return async (input, init)=>{
|
|
9
9
|
if (rateLimiter && !rateLimiter.canRequest()) return Promise.resolve(new Response(`{"limit": ${rateLimiter.maxRequests}}`, {
|
|
10
10
|
status: 429,
|
|
11
11
|
statusText: 'Too Many Requests'
|
|
12
12
|
}));
|
|
13
|
-
|
|
14
|
-
if (!headers.has('apikey') && dataloomKey) headers.set('apikey', dataloomKey);
|
|
15
|
-
return resolvedFetch(input, {
|
|
16
|
-
...init,
|
|
17
|
-
headers
|
|
18
|
-
});
|
|
13
|
+
return resolvedFetch(input, init);
|
|
19
14
|
};
|
|
20
15
|
};
|
|
21
|
-
export {
|
|
16
|
+
export { createRateLimitedFetch, resolveFetch };
|
package/lib/utils/helpers.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { DataloomClientOptions } from './types';
|
|
2
|
-
export declare function stripTrailingSlash(url: string): string;
|
|
3
2
|
export declare const isBrowser: () => boolean;
|
|
4
3
|
export declare function applySettingDefaults(options: DataloomClientOptions, defaults: DataloomClientOptions): Required<DataloomClientOptions>;
|
|
5
4
|
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/utils/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAErD,
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/utils/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAErD,eAAO,MAAM,SAAS,eAAsC,CAAC;AAE7D,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,qBAAqB,EAC9B,QAAQ,EAAE,qBAAqB,GAC9B,QAAQ,CAAC,qBAAqB,CAAC,CAYjC"}
|
package/lib/utils/helpers.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
function stripTrailingSlash(url) {
|
|
2
|
-
return url.replace(/\/$/, '');
|
|
3
|
-
}
|
|
4
1
|
const isBrowser = ()=>'undefined' != typeof window;
|
|
5
2
|
function applySettingDefaults(options, defaults) {
|
|
6
3
|
const { global: globalOptions } = options;
|
|
@@ -14,4 +11,4 @@ function applySettingDefaults(options, defaults) {
|
|
|
14
11
|
}
|
|
15
12
|
};
|
|
16
13
|
}
|
|
17
|
-
export { applySettingDefaults, isBrowser
|
|
14
|
+
export { applySettingDefaults, isBrowser };
|
package/lib/utils/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AccountServicesInjection } from '../service/types';
|
|
1
2
|
export type Fetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
2
3
|
export type OnError = (error: unknown, instance: unknown) => void;
|
|
3
4
|
export type DataloomClientOptions = {
|
|
@@ -30,6 +31,15 @@ export type DataloomClientOptions = {
|
|
|
30
31
|
* Optional. The global hook that will be called when a request fails.
|
|
31
32
|
*/
|
|
32
33
|
onError?: OnError;
|
|
34
|
+
/**
|
|
35
|
+
* 由 client-toolkit 注入的 account services 引用(user/session)。
|
|
36
|
+
* 老调用方式 `(await getDataloom()).service.user/session` 仍可用,但底层实例由本字段提供。
|
|
37
|
+
*
|
|
38
|
+
* 直接构造 DataloomClient(不通过 toolkit)时若未传此字段,访问 service.user/session 会抛错并指向迁移文档。
|
|
39
|
+
*
|
|
40
|
+
* @see docs/superpowers/specs/2026-05-13-auth-sdk-account-services-split-design.md §4.4
|
|
41
|
+
*/
|
|
42
|
+
accountServices?: AccountServicesInjection;
|
|
33
43
|
};
|
|
34
44
|
};
|
|
35
45
|
//# sourceMappingURL=types.d.ts.map
|
package/lib/utils/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,GAAG,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAEjE,MAAM,MAAM,KAAK,GAAG,CAClB,KAAK,EAAE,WAAW,GAAG,GAAG,EACxB,IAAI,CAAC,EAAE,WAAW,KACf,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEvB,MAAM,MAAM,OAAO,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;AAElE,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,CAAC,EAAE;QACP;;WAEG;QACH,SAAS,EAAE,MAAM,CAAC;QAClB;;WAEG;QACH,KAAK,EAAE,MAAM,CAAC;QACd;;WAEG;QACH,KAAK,CAAC,EAAE,KAAK,CAAC;QACd;;WAEG;QACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAEjC;;WAEG;QACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;QAE5B;;WAEG;QACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAE1B;;WAEG;QACH,OAAO,CAAC,EAAE,OAAO,CAAC;QAElB;;;;;;;WAOG;QACH,eAAe,CAAC,EAAE,wBAAwB,CAAC;KAC5C,CAAC;CACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { type DataloomServiceOptions, type DataloomServiceResponse, type ExtraInfo, type Fetch, type FetchOptions, type OnRequestErrorType, ServiceName } from '../utils/types';
|
|
2
|
-
export default abstract class DataloomServiceBase {
|
|
3
|
-
protected baseUrl: string;
|
|
4
|
-
protected headers: {
|
|
5
|
-
[key: string]: string;
|
|
6
|
-
};
|
|
7
|
-
protected fetch: Fetch;
|
|
8
|
-
protected logger: boolean;
|
|
9
|
-
protected serviceName: ServiceName;
|
|
10
|
-
protected brandId: string;
|
|
11
|
-
protected bizSource: string;
|
|
12
|
-
protected appId: string;
|
|
13
|
-
protected onRequestError?: (error: OnRequestErrorType) => void;
|
|
14
|
-
constructor(baseUrl: string, options: DataloomServiceOptions);
|
|
15
|
-
fetchData<T>(url: string, options: FetchOptions, extras?: ExtraInfo): Promise<DataloomServiceResponse<T>>;
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=DataloomServiceBase.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DataloomServiceBase.d.ts","sourceRoot":"","sources":["../../../src/service/services/DataloomServiceBase.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC5B,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,WAAW,EACZ,MAAM,gBAAgB,CAAC;AAExB,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,mBAAmB;IAC/C,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,OAAO,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAC7C,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC;IACvB,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC;IAC1B,SAAS,CAAC,WAAW,EAAE,WAAW,CAAC;IACnC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,SAAS,EAAE,MAAM,CAAC;IAC5B,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,CAAC;gBAEnD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,sBAAsB;IAoBtD,SAAS,CAAC,CAAC,EACf,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,YAAY,EACrB,MAAM,CAAC,EAAE,SAAS,GACjB,OAAO,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC;CAsIvC"}
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { getCookieByName, serializeSessionBrandId } from "../utils/helpers.js";
|
|
2
|
-
import { logRequest, logResponse } from "../utils/logger.js";
|
|
3
|
-
import { traceIdGenerator } from "../utils/trace-id.js";
|
|
4
|
-
import { ServiceName } from "../utils/types.js";
|
|
5
|
-
class DataloomServiceBase {
|
|
6
|
-
constructor(baseUrl, options){
|
|
7
|
-
this.baseUrl = baseUrl;
|
|
8
|
-
this.headers = {
|
|
9
|
-
...options.headers,
|
|
10
|
-
'X-Suda-Csrf-Token': getCookieByName('suda-csrf-token')
|
|
11
|
-
};
|
|
12
|
-
this.logger = options.logger ?? false;
|
|
13
|
-
this.serviceName = ServiceName.DEFAULT;
|
|
14
|
-
this.brandId = serializeSessionBrandId(options.brandName);
|
|
15
|
-
this.bizSource = options.brandName;
|
|
16
|
-
this.appId = options.appId;
|
|
17
|
-
this.onRequestError = options.onRequestError;
|
|
18
|
-
if (options.fetch) this.fetch = options.fetch;
|
|
19
|
-
else this.fetch = fetch;
|
|
20
|
-
}
|
|
21
|
-
async fetchData(url, options, extras) {
|
|
22
|
-
const fetchUrl = `${this.baseUrl.toString()}${url}`;
|
|
23
|
-
let traceId = -1;
|
|
24
|
-
if (this.logger) {
|
|
25
|
-
traceId = traceIdGenerator.next();
|
|
26
|
-
logRequest({
|
|
27
|
-
traceId,
|
|
28
|
-
url: fetchUrl,
|
|
29
|
-
method: options.method,
|
|
30
|
-
body: options.body
|
|
31
|
-
}, extras?.psmName);
|
|
32
|
-
}
|
|
33
|
-
try {
|
|
34
|
-
const res = await this.fetch(fetchUrl, {
|
|
35
|
-
method: options.method,
|
|
36
|
-
mode: 'cors',
|
|
37
|
-
redirect: 'manual',
|
|
38
|
-
credentials: 'include',
|
|
39
|
-
headers: this.headers,
|
|
40
|
-
body: JSON.stringify(options.body)
|
|
41
|
-
});
|
|
42
|
-
let error = null;
|
|
43
|
-
let data = null;
|
|
44
|
-
let status = res.status;
|
|
45
|
-
let statusText = res.statusText;
|
|
46
|
-
if (res.ok) {
|
|
47
|
-
const body = await res.text();
|
|
48
|
-
const parsedBody = JSON.parse(body);
|
|
49
|
-
if (parsedBody.status_code && parsedBody.error_msg) {
|
|
50
|
-
data = null;
|
|
51
|
-
error = {
|
|
52
|
-
code: parsedBody.status_code || res.status,
|
|
53
|
-
details: '',
|
|
54
|
-
hint: '',
|
|
55
|
-
message: parsedBody.error_msg || body
|
|
56
|
-
};
|
|
57
|
-
} else {
|
|
58
|
-
data = parsedBody.data;
|
|
59
|
-
error = null;
|
|
60
|
-
}
|
|
61
|
-
} else {
|
|
62
|
-
const body = await res.text();
|
|
63
|
-
const parsedBody = JSON.parse(body);
|
|
64
|
-
try {
|
|
65
|
-
error = 429 === res.status ? {
|
|
66
|
-
code: 429,
|
|
67
|
-
message: 'Too many requests received within 5 seconds.',
|
|
68
|
-
details: '',
|
|
69
|
-
hint: 'Retry after 5 seconds.'
|
|
70
|
-
} : {
|
|
71
|
-
code: parsedBody.status_code || res.status,
|
|
72
|
-
message: parsedBody.error_msg || body,
|
|
73
|
-
details: '',
|
|
74
|
-
hint: ''
|
|
75
|
-
};
|
|
76
|
-
} catch (_e) {
|
|
77
|
-
error = {
|
|
78
|
-
code: parsedBody.status_code || res.status,
|
|
79
|
-
message: parsedBody.error_msg || body,
|
|
80
|
-
details: '',
|
|
81
|
-
hint: ''
|
|
82
|
-
};
|
|
83
|
-
data = null;
|
|
84
|
-
status = 500;
|
|
85
|
-
statusText = 'Dataloom Internal Error';
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
const serviceResponse = {
|
|
89
|
-
data,
|
|
90
|
-
error,
|
|
91
|
-
status,
|
|
92
|
-
statusText
|
|
93
|
-
};
|
|
94
|
-
if (error) this.onRequestError?.({
|
|
95
|
-
...error,
|
|
96
|
-
status,
|
|
97
|
-
statusText
|
|
98
|
-
});
|
|
99
|
-
if (this.logger) logResponse(traceId, serviceResponse, extras?.psmName);
|
|
100
|
-
return serviceResponse;
|
|
101
|
-
} catch (e) {
|
|
102
|
-
const internalError = {
|
|
103
|
-
error: {
|
|
104
|
-
code: 500,
|
|
105
|
-
message: e instanceof Error ? e.message : String(e),
|
|
106
|
-
details: '',
|
|
107
|
-
hint: ''
|
|
108
|
-
},
|
|
109
|
-
status: 500,
|
|
110
|
-
statusText: 'Dataloom Internal Error'
|
|
111
|
-
};
|
|
112
|
-
this.onRequestError?.({
|
|
113
|
-
...internalError.error,
|
|
114
|
-
status: internalError.status,
|
|
115
|
-
statusText: internalError.statusText
|
|
116
|
-
});
|
|
117
|
-
const serviceResponse = {
|
|
118
|
-
data: null,
|
|
119
|
-
...internalError
|
|
120
|
-
};
|
|
121
|
-
if (this.logger) logResponse(traceId, serviceResponse, extras?.psmName);
|
|
122
|
-
return serviceResponse;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
export { DataloomServiceBase as default };
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { DataloomServiceResponse } from '../../utils/types';
|
|
2
|
-
import { ServiceName } from '../../utils/types';
|
|
3
|
-
import DataloomServiceBase from '../DataloomServiceBase';
|
|
4
|
-
import type { SignInRedirectionOptions, UserInfoResponse } from './types';
|
|
5
|
-
export default class SessionService extends DataloomServiceBase {
|
|
6
|
-
serviceName: ServiceName;
|
|
7
|
-
/**
|
|
8
|
-
* Redirect to login page within app runtime environment.
|
|
9
|
-
*/
|
|
10
|
-
redirectToLogin(options?: SignInRedirectionOptions): DataloomServiceResponse<'success'>;
|
|
11
|
-
/**
|
|
12
|
-
* Sign out current user session.
|
|
13
|
-
*/
|
|
14
|
-
signOut(): Promise<DataloomServiceResponse<null>>;
|
|
15
|
-
/**
|
|
16
|
-
* Get current page URL with biz_source parameter
|
|
17
|
-
*/
|
|
18
|
-
getUrlWithBizSource(): string;
|
|
19
|
-
/**
|
|
20
|
-
* Gets the current user information if there is an existing session.
|
|
21
|
-
*/
|
|
22
|
-
getUserInfo(): Promise<DataloomServiceResponse<UserInfoResponse>>;
|
|
23
|
-
/**
|
|
24
|
-
* Navigate to user profile page within app runtime environment.
|
|
25
|
-
*/
|
|
26
|
-
navigateToUserProfile(options?: {
|
|
27
|
-
newTab?: boolean;
|
|
28
|
-
}): {
|
|
29
|
-
data: null;
|
|
30
|
-
error: {
|
|
31
|
-
code: number;
|
|
32
|
-
message: string;
|
|
33
|
-
hint: string;
|
|
34
|
-
details: string;
|
|
35
|
-
};
|
|
36
|
-
status: number;
|
|
37
|
-
statusText: string;
|
|
38
|
-
} | {
|
|
39
|
-
data: string;
|
|
40
|
-
error: null;
|
|
41
|
-
status: number;
|
|
42
|
-
statusText: string;
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/service/services/session-service/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,mBAAmB,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAGV,wBAAwB,EACxB,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAcjB,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,mBAAmB;IACpD,WAAW,cAA8B;IAElD;;OAEG;IACH,eAAe,CACb,OAAO,CAAC,EAAE,wBAAwB,GACjC,uBAAuB,CAAC,SAAS,CAAC;IAsCrC;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,uBAAuB,CAAC,IAAI,CAAC,CAAC;IAyBvD;;OAEG;IACH,mBAAmB,IAAI,MAAM;IAkB7B;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,uBAAuB,CAAC,gBAAgB,CAAC,CAAC;IAuDvE;;OAEG;IACH,qBAAqB,CAAC,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE;;;;;;;;;;;;;;;;CA+BrD"}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { isBrowser } from "../../utils/helpers.js";
|
|
2
|
-
import { ServiceName } from "../../utils/types.js";
|
|
3
|
-
import { reportDataloomException } from "../../../utils/slardar.js";
|
|
4
|
-
import DataloomServiceBase from "../DataloomServiceBase.js";
|
|
5
|
-
const browserEnvError = {
|
|
6
|
-
data: null,
|
|
7
|
-
error: {
|
|
8
|
-
code: 400,
|
|
9
|
-
message: 'Incompatible runtime environment',
|
|
10
|
-
hint: 'Please check if the current environment is browser.',
|
|
11
|
-
details: 'This method can only be invoked in browser environment.'
|
|
12
|
-
},
|
|
13
|
-
status: 400,
|
|
14
|
-
statusText: 'Bad Request'
|
|
15
|
-
};
|
|
16
|
-
class SessionService extends DataloomServiceBase {
|
|
17
|
-
redirectToLogin(options) {
|
|
18
|
-
if (!isBrowser()) {
|
|
19
|
-
reportDataloomException(browserEnvError.error, {
|
|
20
|
-
module: 'session-service',
|
|
21
|
-
method: 'redirectToLogin',
|
|
22
|
-
type: 'runtime'
|
|
23
|
-
});
|
|
24
|
-
console.log('[Dataloom][SessionService.RedirectToLogin] dataloom.service.session.redirectToLogin can only be invoked in browser environment.');
|
|
25
|
-
return browserEnvError;
|
|
26
|
-
}
|
|
27
|
-
const { returnUrl, newTab = false } = options ?? {};
|
|
28
|
-
const encodedRedirectUrl = encodeURIComponent(decodeURIComponent(returnUrl || window.location.href));
|
|
29
|
-
const isSparkFaasPath = window.location.pathname.startsWith('/spark');
|
|
30
|
-
const baseLoginUrl = isSparkFaasPath ? `/spark/faas/${this.appId}/runtime/page/login` : `/app/${this.appId}/runtime/page/login`;
|
|
31
|
-
const loginPageUrl = `${baseLoginUrl}?biz_source=${this.bizSource}&redirect_uri=${encodedRedirectUrl}`;
|
|
32
|
-
if (newTab) window.open(loginPageUrl, '_blank');
|
|
33
|
-
else window.location.href = loginPageUrl;
|
|
34
|
-
return {
|
|
35
|
-
data: 'success',
|
|
36
|
-
error: null,
|
|
37
|
-
status: 200,
|
|
38
|
-
statusText: 'OK'
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
async signOut() {
|
|
42
|
-
if (!isBrowser()) {
|
|
43
|
-
reportDataloomException(browserEnvError.error, {
|
|
44
|
-
module: 'session-service',
|
|
45
|
-
method: 'signOut',
|
|
46
|
-
type: 'runtime'
|
|
47
|
-
});
|
|
48
|
-
console.log('[Dataloom][SessionService.SignOut] dataloom.service.session.signOut can only be invoked in browser environment.');
|
|
49
|
-
return browserEnvError;
|
|
50
|
-
}
|
|
51
|
-
const location = this.getUrlWithBizSource();
|
|
52
|
-
return this.fetchData('/af/runtime/api/v1/account/logout', {
|
|
53
|
-
method: 'POST',
|
|
54
|
-
body: {
|
|
55
|
-
appID: this.appId,
|
|
56
|
-
redirectURI: location
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
getUrlWithBizSource() {
|
|
61
|
-
if (!isBrowser()) {
|
|
62
|
-
reportDataloomException(browserEnvError.error, {
|
|
63
|
-
module: 'session-service',
|
|
64
|
-
method: 'getUrlWithBizSource',
|
|
65
|
-
type: 'runtime'
|
|
66
|
-
});
|
|
67
|
-
console.log('[Dataloom][SessionService.GetUrlWithBizSource] dataloom.service.session.getUrlWithBizSource can only be invoked in browser environment.');
|
|
68
|
-
return '';
|
|
69
|
-
}
|
|
70
|
-
const currentUrl = new URL(window.location.href);
|
|
71
|
-
currentUrl.searchParams.set('biz_source', this.bizSource);
|
|
72
|
-
return currentUrl.toString();
|
|
73
|
-
}
|
|
74
|
-
async getUserInfo() {
|
|
75
|
-
if (!isBrowser()) {
|
|
76
|
-
reportDataloomException(browserEnvError.error, {
|
|
77
|
-
module: 'session-service',
|
|
78
|
-
method: 'getUserInfo',
|
|
79
|
-
type: 'runtime'
|
|
80
|
-
});
|
|
81
|
-
console.log('[Dataloom][SessionService.GetUserInfo] dataloom.service.session.getUserInfo can only be invoked in browser environment.');
|
|
82
|
-
return Promise.resolve(browserEnvError);
|
|
83
|
-
}
|
|
84
|
-
const url = `/app/${this.appId}/__runtime__/api/v1/account/login/user`;
|
|
85
|
-
const urlObj = new URL(globalThis.location.href);
|
|
86
|
-
const pathSegments = urlObj.hostname.split('.');
|
|
87
|
-
const tenantDomainName = pathSegments[0] ?? '';
|
|
88
|
-
const response = await this.fetchData(url, {
|
|
89
|
-
method: 'POST',
|
|
90
|
-
body: {
|
|
91
|
-
appID: this.appId,
|
|
92
|
-
tenantDomainName
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
const userInfoResponse = {
|
|
96
|
-
data: {
|
|
97
|
-
user_info: {
|
|
98
|
-
user_id: response.data?.userInfo?.userID,
|
|
99
|
-
name: response.data?.userInfo?.name,
|
|
100
|
-
avatar: response.data?.userInfo?.avatar,
|
|
101
|
-
email: response.data?.userInfo?.email,
|
|
102
|
-
phone_number: response.data?.userInfo?.desensitizedPhoneNumber
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
error: null,
|
|
106
|
-
status: response.status,
|
|
107
|
-
statusText: response.statusText
|
|
108
|
-
};
|
|
109
|
-
return userInfoResponse;
|
|
110
|
-
}
|
|
111
|
-
navigateToUserProfile(options) {
|
|
112
|
-
if (!isBrowser()) {
|
|
113
|
-
reportDataloomException(browserEnvError.error, {
|
|
114
|
-
module: 'session-service',
|
|
115
|
-
method: 'navigateToUserProfile',
|
|
116
|
-
type: 'runtime'
|
|
117
|
-
});
|
|
118
|
-
console.log('[Dataloom][SessionService.NavigateToUserProfile] dataloom.service.session.navigateToUserProfile can only be invoked in browser environment.');
|
|
119
|
-
return browserEnvError;
|
|
120
|
-
}
|
|
121
|
-
const { newTab = false } = options ?? {};
|
|
122
|
-
const encodedReturnUrl = encodeURIComponent(window.location.href);
|
|
123
|
-
const profilePageUrl = `/suda/user?brand=${this.brandId}&returnUrl=${encodedReturnUrl}&appId=${this.appId}`;
|
|
124
|
-
if (newTab) window.open(profilePageUrl, '_blank');
|
|
125
|
-
else window.location.href = profilePageUrl;
|
|
126
|
-
return {
|
|
127
|
-
data: 'success',
|
|
128
|
-
error: null,
|
|
129
|
-
status: 200,
|
|
130
|
-
statusText: 'OK'
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
constructor(...args){
|
|
134
|
-
super(...args), this.serviceName = ServiceName.SessionService;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
export { SessionService as default };
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export interface I18n {
|
|
2
|
-
language_code: number;
|
|
3
|
-
text: string;
|
|
4
|
-
}
|
|
5
|
-
export type I18ns = I18n[];
|
|
6
|
-
export interface Avatar {
|
|
7
|
-
source?: string;
|
|
8
|
-
image?: {
|
|
9
|
-
large?: string;
|
|
10
|
-
};
|
|
11
|
-
color?: string;
|
|
12
|
-
}
|
|
13
|
-
export interface SignInRedirectionOptions {
|
|
14
|
-
/**
|
|
15
|
-
* The URL to redirect to after a successful login. Defaults to the current URL.
|
|
16
|
-
*/
|
|
17
|
-
returnUrl?: string;
|
|
18
|
-
/**
|
|
19
|
-
* Whether to open the login page in a new tab. Defaults to `false`.
|
|
20
|
-
*/
|
|
21
|
-
newTab?: boolean;
|
|
22
|
-
}
|
|
23
|
-
export interface UserBaseInfo {
|
|
24
|
-
user_id?: number;
|
|
25
|
-
name?: I18ns;
|
|
26
|
-
avatar?: Avatar;
|
|
27
|
-
email?: string;
|
|
28
|
-
phone_number?: string;
|
|
29
|
-
tenant_name?: string;
|
|
30
|
-
}
|
|
31
|
-
export interface UserInfoResponse {
|
|
32
|
-
user_info?: UserBaseInfo;
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/service/services/session-service/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,IAAI;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,KAAK,GAAG,IAAI,EAAE,CAAC;AAE3B,MAAM,WAAW,MAAM;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE;QACN,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,KAAK,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,CAAC,EAAE,YAAY,CAAC;CAC1B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/service/services/types.ts"],"names":[],"mappings":"AACA,oBAAY,aAAa;IACvB,WAAW,IAAI;IACf,QAAQ,IAAI,CAAE,MAAM;IACpB,MAAM,IAAI,CAAE,MAAM;IAClB,QAAQ,IAAI,CAAE,KAAK;IACnB,UAAU,IAAI;CACf;AAGD,oBAAY,UAAU;IACpB,MAAM,IAAI,CAAE,KAAK;IACjB,QAAQ,IAAI;CACb"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
var types_AccountStatus = /*#__PURE__*/ function(AccountStatus) {
|
|
2
|
-
AccountStatus[AccountStatus["Unspecified"] = 0] = "Unspecified";
|
|
3
|
-
AccountStatus[AccountStatus["Inactive"] = 1] = "Inactive";
|
|
4
|
-
AccountStatus[AccountStatus["Active"] = 2] = "Active";
|
|
5
|
-
AccountStatus[AccountStatus["Disabled"] = 3] = "Disabled";
|
|
6
|
-
AccountStatus[AccountStatus["Terminated"] = 4] = "Terminated";
|
|
7
|
-
return AccountStatus;
|
|
8
|
-
}({});
|
|
9
|
-
var types_UserStatus = /*#__PURE__*/ function(UserStatus) {
|
|
10
|
-
UserStatus[UserStatus["active"] = 1] = "active";
|
|
11
|
-
UserStatus[UserStatus["inactive"] = 2] = "inactive";
|
|
12
|
-
return UserStatus;
|
|
13
|
-
}({});
|
|
14
|
-
export { types_AccountStatus as AccountStatus, types_UserStatus as UserStatus };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type DataloomServiceResponse, ServiceName } from '../../utils/types';
|
|
2
|
-
import DataloomServiceBase from '../DataloomServiceBase';
|
|
3
|
-
import type { SearchParams, UserResponse } from './types';
|
|
4
|
-
export default class UserService extends DataloomServiceBase {
|
|
5
|
-
serviceName: ServiceName;
|
|
6
|
-
search(params: SearchParams): Promise<DataloomServiceResponse<UserResponse>>;
|
|
7
|
-
getByIds(ids: string[] | number[]): Promise<DataloomServiceResponse<UserResponse>>;
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/service/services/user-service/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,uBAAuB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,mBAAmB,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAEV,YAAY,EAEZ,YAAY,EACb,MAAM,SAAS,CAAC;AAEjB,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,mBAAmB;IACjD,WAAW,cAA2B;IAEzC,MAAM,CACV,MAAM,EAAE,YAAY,GACnB,OAAO,CAAC,uBAAuB,CAAC,YAAY,CAAC,CAAC;IAsC3C,QAAQ,CACZ,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,GACvB,OAAO,CAAC,uBAAuB,CAAC,YAAY,CAAC,CAAC;CAmClD"}
|