@lark-apaas/dataloom 0.1.4-alpha.7 → 0.1.4-alpha.9
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 +28 -18
- 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 +4 -0
- package/lib/storage/packages/StorageFileApi.d.ts.map +1 -1
- package/lib/storage/packages/StorageFileApi.js +35 -46
- 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
|
@@ -122,6 +122,10 @@ export default class StorageFileApi {
|
|
|
122
122
|
/**
|
|
123
123
|
* Downloads a file from a private bucket. For public buckets, make a request to the URL returned from `getPublicUrl` instead.
|
|
124
124
|
*
|
|
125
|
+
* 实现:先调 createSignedUrl 拿一个 10 分钟有效的签名链接,再用 fetch 直接拉
|
|
126
|
+
* 该链接的二进制返回。绕开「直连 storage GET → 302 跳 CDN,CDN 响应头
|
|
127
|
+
* `access-control-allow-origin: *` 与 `credentials: 'include'` 冲突」的跨域问题。
|
|
128
|
+
*
|
|
125
129
|
* @param path The full path and file name of the file to be downloaded. For example `folder/image.png`.
|
|
126
130
|
* @param options.transform Transform the asset before serving it to the client.
|
|
127
131
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StorageFileApi.d.ts","sourceRoot":"","sources":["../../../src/storage/packages/StorageFileApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,EAEb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,KAAK,EAA0B,MAAM,eAAe,CAAC;AASnE,OAAO,KAAK,EACV,eAAe,EACf,QAAQ,EACR,UAAU,EACV,WAAW,EACX,aAAa,EACb,kBAAkB,EAElB,aAAa,EACb,gBAAgB,EAChB,cAAc,EACf,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"StorageFileApi.d.ts","sourceRoot":"","sources":["../../../src/storage/packages/StorageFileApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,EAEb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,KAAK,EAA0B,MAAM,eAAe,CAAC;AASnE,OAAO,KAAK,EACV,eAAe,EACf,QAAQ,EACR,UAAU,EACV,WAAW,EACX,aAAa,EACb,kBAAkB,EAElB,aAAa,EACb,gBAAgB,EAChB,cAAc,EACf,MAAM,eAAe,CAAC;AA0DvB,MAAM,CAAC,OAAO,OAAO,cAAc;IACjC,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,OAAO,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAC7C,SAAS,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC5B,SAAS,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC;IACvB,SAAS,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;IAClC,SAAS,CAAC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,CAAC;gB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IAAI,CAAC;QACX,KAAK,EAAE,YAAY,CAAC;KACrB,CACJ;IAuDD;;;;OAIG;IACG,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAClC;QACE,IAAI,EAAE,UAAU,EAAE,CAAC;QACnB,KAAK,EAAE,IAAI,CAAC;KACb,GACD;QACE,IAAI,EAAE,IAAI,CAAC;QACX,KAAK,EAAE,YAAY,CAAC;KACrB,CACJ;IAoCD;;;;OAIG;IACG,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CACrC;QACE,IAAI,EAAE,cAAc,CAAC;QACrB,KAAK,EAAE,IAAI,CAAC;KACb,GACD;QACE,IAAI,EAAE,IAAI,CAAC;QACX,KAAK,EAAE,YAAY,CAAC;KACrB,CACJ;IA6FD;;;;OAIG;IACG,IAAI,CACR,IAAI,CAAC,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,aAAa,EACvB,UAAU,CAAC,EAAE,eAAe,GAC3B,OAAO,CACN;QACE,IAAI,EAAE,UAAU,EAAE,CAAC;QACnB,KAAK,EAAE,IAAI,CAAC;KACb,GACD;QACE,IAAI,EAAE,IAAI,CAAC;QACX,KAAK,EAAE,YAAY,CAAC;KACrB,CACJ;IAwCD,+BAA+B,CAAC,QAAQ,EAAE,MAAM;IAMhD,SAAS,CAAC,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAI1D,QAAQ,CAAC,IAAI,EAAE,MAAM;IAOrB,OAAO,CAAC,aAAa;IAMrB,OAAO,CAAC,mBAAmB;IAQ3B,OAAO,CAAC,mBAAmB;IAM3B;;;;OAIG;IACH,OAAO,CAAC,gCAAgC;IAsBxC;;OAEG;YACW,qBAAqB;CAuBpC"}
|
|
@@ -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,
|
|
@@ -76,12 +76,13 @@ class StorageFileApi {
|
|
|
76
76
|
}, void 0, {
|
|
77
77
|
psmName: 'Storage.Upload.Callback'
|
|
78
78
|
});
|
|
79
|
+
const callbackData = callbackRes?.data;
|
|
79
80
|
return {
|
|
80
|
-
data:
|
|
81
|
-
id: '',
|
|
82
|
-
file_path: '',
|
|
83
|
-
bucket_id: '',
|
|
84
|
-
download_url: ''
|
|
81
|
+
data: {
|
|
82
|
+
id: callbackData?.id ?? '',
|
|
83
|
+
file_path: callbackData?.filePath ?? '',
|
|
84
|
+
bucket_id: callbackData?.bucketID ?? '',
|
|
85
|
+
download_url: callbackData?.downloadURL ?? ''
|
|
85
86
|
},
|
|
86
87
|
error: null
|
|
87
88
|
};
|
|
@@ -113,7 +114,7 @@ class StorageFileApi {
|
|
|
113
114
|
try {
|
|
114
115
|
const _path = this._getFinalPath(path);
|
|
115
116
|
const res = await post(this.fetch, `${this.url}/object/sign/${_path}`, {
|
|
116
|
-
|
|
117
|
+
expiresIn: toValidExpiresIn(expiresIn)
|
|
117
118
|
}, {
|
|
118
119
|
headers: this.headers,
|
|
119
120
|
logFetch: this.loggerEnabled,
|
|
@@ -140,7 +141,7 @@ class StorageFileApi {
|
|
|
140
141
|
try {
|
|
141
142
|
const _paths = paths.map((path)=>this._retrieveFilePathFromDownloadUrl(path));
|
|
142
143
|
const res = await post(this.fetch, `${this.url}/object/sign/${this.bucketId}`, {
|
|
143
|
-
|
|
144
|
+
expiresIn: toValidExpiresIn(expiresIn),
|
|
144
145
|
paths: _paths
|
|
145
146
|
}, {
|
|
146
147
|
headers: this.headers,
|
|
@@ -166,42 +167,30 @@ class StorageFileApi {
|
|
|
166
167
|
}
|
|
167
168
|
async download(path, _options) {
|
|
168
169
|
try {
|
|
169
|
-
const
|
|
170
|
-
const
|
|
171
|
-
|
|
170
|
+
const SIGNED_URL_EXPIRES_IN_SECONDS = 600;
|
|
171
|
+
const { data: signed, error: signedError } = await this.createSignedUrl(path, SIGNED_URL_EXPIRES_IN_SECONDS);
|
|
172
|
+
if (signedError || !signed?.signedUrl) return {
|
|
173
|
+
data: null,
|
|
174
|
+
error: signedError ?? new StorageError('failed to create signed url for download')
|
|
175
|
+
};
|
|
176
|
+
const res = await get(this.fetch, signed.signedUrl, {
|
|
172
177
|
noResolveJson: true,
|
|
178
|
+
noCredentials: true,
|
|
173
179
|
logFetch: this.loggerEnabled,
|
|
174
180
|
onRequestError: this.onRequestError
|
|
175
181
|
}, void 0, {
|
|
176
182
|
psmName: 'Storage.Download'
|
|
177
183
|
});
|
|
178
|
-
if (res.
|
|
179
|
-
const resBody = await res.blob();
|
|
180
|
-
return {
|
|
181
|
-
data: resBody,
|
|
182
|
-
error: null
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
const resBody = await res.json();
|
|
186
|
-
return {
|
|
184
|
+
if (!res.ok) return {
|
|
187
185
|
data: null,
|
|
188
|
-
error:
|
|
186
|
+
error: new StorageError(`download file error: ${res.status} ${res.statusText}`)
|
|
187
|
+
};
|
|
188
|
+
const blob = await res.blob();
|
|
189
|
+
return {
|
|
190
|
+
data: blob,
|
|
191
|
+
error: null
|
|
189
192
|
};
|
|
190
193
|
} catch (error) {
|
|
191
|
-
if (error && 'object' == typeof error && 'originalError' in error) {
|
|
192
|
-
const originalError = error.originalError;
|
|
193
|
-
if (originalError instanceof Response && originalError.redirected) try {
|
|
194
|
-
return {
|
|
195
|
-
data: null,
|
|
196
|
-
error: new StorageError(await originalError.text())
|
|
197
|
-
};
|
|
198
|
-
} catch (_e) {
|
|
199
|
-
return {
|
|
200
|
-
data: null,
|
|
201
|
-
error: new StorageUnknownError('download file error', error)
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
194
|
if (isCustomError(error) || isStorageError(error)) return {
|
|
206
195
|
data: null,
|
|
207
196
|
error: error
|
|
@@ -359,7 +348,7 @@ class StorageFileApi {
|
|
|
359
348
|
return '';
|
|
360
349
|
}
|
|
361
350
|
async _copyWithinVolcEngine(url) {
|
|
362
|
-
const res = await post(this.fetch, `${this.url}/
|
|
351
|
+
const res = await post(this.fetch, `${this.url}/object/${this.bucketId}/copy`, {
|
|
363
352
|
source: {
|
|
364
353
|
type: 'externalTOS',
|
|
365
354
|
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"}
|