@lark-apaas/dataloom 0.1.3-beta.2 → 0.1.4-alpha.0
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 +6 -6
- package/lib/DataloomClient.d.ts.map +1 -1
- package/lib/DataloomClient.js +5 -9
- 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 +1 -1
- package/lib/storage/StorageClient.d.ts +1 -2
- package/lib/storage/StorageClient.d.ts.map +1 -1
- package/lib/storage/StorageClient.js +4 -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 +15 -0
- package/lib/storage/utils/csrf.d.ts.map +1 -0
- package/lib/storage/utils/csrf.js +12 -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/package.json +1 -1
package/README.md
CHANGED
|
@@ -47,18 +47,17 @@ import { createClient } from '@lark-apaas/dataloom';
|
|
|
47
47
|
```ts
|
|
48
48
|
import { createClient } from '@lark-apaas/dataloom';
|
|
49
49
|
|
|
50
|
-
const client = createClient(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
global: {
|
|
55
|
-
brandName: 'miaoda',
|
|
56
|
-
appId: 'app_xxx',
|
|
57
|
-
},
|
|
50
|
+
const client = createClient({
|
|
51
|
+
global: {
|
|
52
|
+
brandName: 'miaoda',
|
|
53
|
+
appId: 'app_xxx',
|
|
58
54
|
},
|
|
59
|
-
);
|
|
55
|
+
});
|
|
60
56
|
```
|
|
61
57
|
|
|
58
|
+
> storage 走 cookie session 鉴权(runtime endpoint 自动携带 cookie),不再需要传入
|
|
59
|
+
> `dataloomUrl` / `dataloomKey`;appId 通过 `options.global.appId` 传入即可。
|
|
60
|
+
|
|
62
61
|
创建完成后,可以通过以下入口访问能力:
|
|
63
62
|
|
|
64
63
|
- `client.service.user`
|
|
@@ -70,21 +69,18 @@ const client = createClient(
|
|
|
70
69
|
### `createClient(...)`
|
|
71
70
|
|
|
72
71
|
```ts
|
|
73
|
-
createClient(
|
|
74
|
-
dataloomUrl: string,
|
|
75
|
-
dataloomKey: string,
|
|
76
|
-
options?: DataloomClientOptions,
|
|
77
|
-
)
|
|
72
|
+
createClient(options?: DataloomClientOptions)
|
|
78
73
|
```
|
|
79
74
|
|
|
80
75
|
#### 入参
|
|
81
76
|
|
|
82
77
|
| 参数 | 类型 | 必填 | 说明 |
|
|
83
78
|
| --- | --- | --- | --- |
|
|
84
|
-
| `dataloomUrl` | `string` | 是 | Dataloom 服务地址 |
|
|
85
|
-
| `dataloomKey` | `string` | 是 | 访问 Dataloom 的 key |
|
|
86
79
|
| `options` | `DataloomClientOptions` | 否 | 初始化配置 |
|
|
87
80
|
|
|
81
|
+
> storage 走 cookie session 鉴权,不再需要 `dataloomUrl` / `dataloomKey`;
|
|
82
|
+
> appId 通过 `options.global.appId` 传入。
|
|
83
|
+
|
|
88
84
|
#### 返回
|
|
89
85
|
|
|
90
86
|
| 返回值 | 类型 | 说明 |
|
|
@@ -124,24 +120,20 @@ type DataloomClientOptions = {
|
|
|
124
120
|
完整示例:
|
|
125
121
|
|
|
126
122
|
```ts
|
|
127
|
-
const client = createClient(
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
requestRateLimit: 5,
|
|
139
|
-
onError(error, instance) {
|
|
140
|
-
console.error('[dataloom error]', error, instance);
|
|
141
|
-
},
|
|
123
|
+
const client = createClient({
|
|
124
|
+
global: {
|
|
125
|
+
brandName: 'miaoda',
|
|
126
|
+
appId: 'app_xxx',
|
|
127
|
+
headers: {
|
|
128
|
+
'x-custom-header': 'demo',
|
|
129
|
+
},
|
|
130
|
+
enableDataloomLog: false,
|
|
131
|
+
requestRateLimit: 5,
|
|
132
|
+
onError(error, instance) {
|
|
133
|
+
console.error('[dataloom error]', error, instance);
|
|
142
134
|
},
|
|
143
135
|
},
|
|
144
|
-
);
|
|
136
|
+
});
|
|
145
137
|
```
|
|
146
138
|
|
|
147
139
|
## Service API
|
package/lib/DataloomClient.d.ts
CHANGED
|
@@ -9,22 +9,22 @@ import type { OnRequestErrorType } from './storage/libs/types';
|
|
|
9
9
|
* An isomorphic Javascript client for interacting with Dataloom service and storage.
|
|
10
10
|
*/
|
|
11
11
|
export default class DataloomClient {
|
|
12
|
-
protected dataloomUrl: string;
|
|
13
|
-
protected dataloomKey: string;
|
|
14
12
|
service: DataloomService;
|
|
15
13
|
storage: StorageClient;
|
|
16
|
-
protected storageUrl: string;
|
|
17
14
|
protected fetch?: Fetch;
|
|
18
15
|
protected rateLimiter?: RateLimiter;
|
|
19
16
|
protected onRequestError: (error: OnRequestErrorType) => void;
|
|
20
17
|
protected headers: Record<string, string>;
|
|
21
18
|
/**
|
|
22
19
|
* Create a new client for use in the browser.
|
|
23
|
-
*
|
|
24
|
-
*
|
|
20
|
+
*
|
|
21
|
+
* Storage requests target the `/app/:appId/__runtime__/api/v1/storage`
|
|
22
|
+
* runtime endpoints and rely on cookie session authentication.
|
|
23
|
+
*
|
|
24
|
+
* @param options.global.appId The appId used to build the storage runtime path.
|
|
25
25
|
* @param options.global.fetch A custom fetch implementation.
|
|
26
26
|
* @param options.global.headers Any additional headers to send with each network request.
|
|
27
27
|
*/
|
|
28
|
-
constructor(
|
|
28
|
+
constructor(options?: DataloomClientOptions);
|
|
29
29
|
}
|
|
30
30
|
//# sourceMappingURL=DataloomClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataloomClient.d.ts","sourceRoot":"","sources":["../src/DataloomClient.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,eAAe,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAK1C,OAAO,KAAK,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE/D;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,cAAc;
|
|
1
|
+
{"version":3,"file":"DataloomClient.d.ts","sourceRoot":"","sources":["../src/DataloomClient.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,eAAe,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAK1C,OAAO,KAAK,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE/D;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,cAAc;IACjC,OAAO,EAAE,eAAe,CAAC;IACzB,OAAO,EAAE,aAAa,CAAC;IAEvB,SAAS,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IACxB,SAAS,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC;IACpC,SAAS,CAAC,cAAc,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,CAAC;IAE9D,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE1C;;;;;;;;;OASG;gBACS,OAAO,CAAC,EAAE,qBAAqB;CAuC5C"}
|
package/lib/DataloomClient.js
CHANGED
|
@@ -2,15 +2,11 @@ import RateLimiter from "./RateLimiter.js";
|
|
|
2
2
|
import service from "./service/index.js";
|
|
3
3
|
import { StorageClient } from "./storage/index.js";
|
|
4
4
|
import { DEFAULT_GLOBAL_OPTIONS } from "./utils/constants.js";
|
|
5
|
-
import {
|
|
6
|
-
import { applySettingDefaults
|
|
5
|
+
import { createRateLimitedFetch } from "./utils/fetch.js";
|
|
6
|
+
import { applySettingDefaults } from "./utils/helpers.js";
|
|
7
7
|
import { reportDataloomException } from "./utils/slardar.js";
|
|
8
8
|
class DataloomClient {
|
|
9
|
-
constructor(
|
|
10
|
-
this.dataloomUrl = dataloomUrl;
|
|
11
|
-
this.dataloomKey = dataloomKey;
|
|
12
|
-
const normalizedDataloomUrl = stripTrailingSlash(dataloomUrl);
|
|
13
|
-
this.storageUrl = `${normalizedDataloomUrl}/storage`;
|
|
9
|
+
constructor(options){
|
|
14
10
|
const DEFAULTS = {
|
|
15
11
|
global: DEFAULT_GLOBAL_OPTIONS
|
|
16
12
|
};
|
|
@@ -25,11 +21,11 @@ class DataloomClient {
|
|
|
25
21
|
if (settings.global.onError) settings.global.onError(error, this);
|
|
26
22
|
};
|
|
27
23
|
if (settings.global.requestRateLimit && settings.global.requestRateLimit > 0) this.rateLimiter = new RateLimiter(settings.global.requestRateLimit);
|
|
28
|
-
this.fetch =
|
|
24
|
+
this.fetch = createRateLimitedFetch(this.rateLimiter, settings.global.fetch);
|
|
29
25
|
this.service = new service({
|
|
30
26
|
accountServices: settings.global.accountServices
|
|
31
27
|
});
|
|
32
|
-
this.storage = new StorageClient(this.
|
|
28
|
+
this.storage = new StorageClient(this.headers, this.fetch, {
|
|
33
29
|
enableLogger: settings.global.enableDataloomLog,
|
|
34
30
|
onRequestError: this.onRequestError,
|
|
35
31
|
appId: settings.global.appId
|
package/lib/index.d.ts
CHANGED
|
@@ -4,6 +4,10 @@ export { default as DataloomClient } from './DataloomClient';
|
|
|
4
4
|
export type { DataloomClientOptions } from './utils/types';
|
|
5
5
|
/**
|
|
6
6
|
* Creates a new Dataloom Client.
|
|
7
|
+
*
|
|
8
|
+
* Storage requests are authenticated via cookie session against the
|
|
9
|
+
* `/app/:appId/__runtime__/api/v1/storage` runtime endpoints, so no
|
|
10
|
+
* dataloom url / key needs to be supplied any more.
|
|
7
11
|
*/
|
|
8
|
-
export declare const createClient: (
|
|
12
|
+
export declare const createClient: (options?: DataloomClientOptions) => DataloomClient;
|
|
9
13
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7D,YAAY,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAE3D
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7D,YAAY,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAE3D;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,GACvB,UAAU,qBAAqB,KAC9B,cAEF,CAAC"}
|
package/lib/index.js
CHANGED
package/lib/service/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface DataloomServiceOptions {
|
|
|
11
11
|
*
|
|
12
12
|
* 注入路径:
|
|
13
13
|
* client-toolkit / client-toolkit-lite
|
|
14
|
-
* → createClient(
|
|
14
|
+
* → createClient({ global: { accountServices: { user, session } } })
|
|
15
15
|
* → new DataloomClient(...)
|
|
16
16
|
* → new DataloomService({ accountServices })
|
|
17
17
|
*
|
|
@@ -8,7 +8,6 @@ export interface StorageClientOptions {
|
|
|
8
8
|
onRequestError: (error: OnRequestErrorType) => void;
|
|
9
9
|
}
|
|
10
10
|
export declare class StorageClient {
|
|
11
|
-
protected url: string;
|
|
12
11
|
protected headers: {
|
|
13
12
|
[key: string]: string;
|
|
14
13
|
};
|
|
@@ -16,7 +15,7 @@ export declare class StorageClient {
|
|
|
16
15
|
protected fetch: Fetch;
|
|
17
16
|
protected loggerEnabled?: boolean;
|
|
18
17
|
protected onRequestError?: (error: OnRequestErrorType) => void;
|
|
19
|
-
constructor(
|
|
18
|
+
constructor(headers?: {
|
|
20
19
|
[key: string]: string;
|
|
21
20
|
}, fetch?: Fetch, opts?: StorageClientOptions);
|
|
22
21
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StorageClient.d.ts","sourceRoot":"","sources":["../../src/storage/StorageClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAG1C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,cAAc,MAAM,2BAA2B,CAAC;AAEvD,MAAM,WAAW,oBAAoB;IACnC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,CAAC;CACrD;AAED,qBAAa,aAAa;IACxB,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"StorageClient.d.ts","sourceRoot":"","sources":["../../src/storage/StorageClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAG1C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,cAAc,MAAM,2BAA2B,CAAC;AAEvD,MAAM,WAAW,oBAAoB;IACnC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,CAAC;CACrD;AAED,qBAAa,aAAa;IACxB,SAAS,CAAC,OAAO,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAC7C,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;gBAG7D,OAAO,GAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAO,EACvC,KAAK,CAAC,EAAE,KAAK,EACb,IAAI,CAAC,EAAE,oBAAoB;IAY7B;;;;OAIG;IACH,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,cAAc;CAejC"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { DEFAULT_HEADERS } from "./libs/constants.js";
|
|
2
|
-
import { resolveFetch } from "./libs/helpers.js";
|
|
2
|
+
import { getStorageBaseUrl, resolveFetch } from "./libs/helpers.js";
|
|
3
3
|
import StorageFileApi from "./packages/StorageFileApi.js";
|
|
4
4
|
class StorageClient {
|
|
5
|
-
constructor(
|
|
6
|
-
this.url = url;
|
|
5
|
+
constructor(headers = {}, fetch, opts){
|
|
7
6
|
this.headers = {
|
|
8
7
|
...DEFAULT_HEADERS,
|
|
9
8
|
...headers
|
|
@@ -14,7 +13,8 @@ class StorageClient {
|
|
|
14
13
|
if (opts?.enableLogger) this.loggerEnabled = true;
|
|
15
14
|
}
|
|
16
15
|
from(id) {
|
|
17
|
-
|
|
16
|
+
const url = getStorageBaseUrl(this.appId);
|
|
17
|
+
return new StorageFileApi(url, this.headers, id, this.appId, this.fetch, this.loggerEnabled, this.onRequestError);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
export { StorageClient };
|
|
@@ -7,6 +7,12 @@ export interface FetchOptions {
|
|
|
7
7
|
duplex?: string;
|
|
8
8
|
noResolveJson?: boolean;
|
|
9
9
|
logFetch?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Skip attaching `credentials: 'include'`. Used for the external TOS PUT
|
|
12
|
+
* step, which targets a cross-origin presigned URL and must not send our
|
|
13
|
+
* session cookies.
|
|
14
|
+
*/
|
|
15
|
+
noCredentials?: boolean;
|
|
10
16
|
onRequestError?: (error: OnRequestErrorType) => void;
|
|
11
17
|
}
|
|
12
18
|
export interface ExtraInfo {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../src/storage/libs/fetch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../src/storage/libs/fetch.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAEnE,MAAM,MAAM,KAAK,GAAG,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAExF,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,EAAE;QACR,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;KACvB,CAAC;IACF,MAAM,CAAC,EAAE,MAAM,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EAAE,KAAK,EACd,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,YAAY,EACtB,UAAU,CAAC,EAAE,eAAe,EAC5B,MAAM,CAAC,EAAE,SAAS,GACjB,OAAO,CAAC,OAAO,CAAC,CAUlB"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { logRequest, logResponse } from "../utils/logger.js";
|
|
2
2
|
import { traceIdGenerator } from "../utils/trace-id.js";
|
|
3
|
+
import { getCsrfToken } from "../utils/csrf.js";
|
|
3
4
|
import { reportDataloomException } from "../../utils/slardar.js";
|
|
4
5
|
import { StorageApiError, StorageUnknownError, isSdkRateLimited, isServerCustomError } from "./errors.js";
|
|
5
6
|
import { isPlainObject, resolveResponse } from "./helpers.js";
|
|
@@ -56,14 +57,23 @@ const handleError = async (error, reject, options)=>{
|
|
|
56
57
|
}
|
|
57
58
|
};
|
|
58
59
|
const _getRequestParams = (method, options, parameters, body)=>{
|
|
60
|
+
const csrfToken = options?.noCredentials || 'GET' === method ? '' : getCsrfToken();
|
|
61
|
+
const csrfHeaders = csrfToken ? {
|
|
62
|
+
'X-Suda-Csrf-Token': csrfToken
|
|
63
|
+
} : {};
|
|
59
64
|
const params = {
|
|
60
65
|
method,
|
|
61
|
-
headers:
|
|
66
|
+
headers: {
|
|
67
|
+
...csrfHeaders,
|
|
68
|
+
...options?.headers
|
|
69
|
+
}
|
|
62
70
|
};
|
|
71
|
+
if (!options?.noCredentials) params.credentials = 'include';
|
|
63
72
|
if ('GET' === method || !body) return params;
|
|
64
73
|
if (isPlainObject(body)) {
|
|
65
74
|
params.headers = {
|
|
66
75
|
'Content-Type': 'application/json',
|
|
76
|
+
...csrfHeaders,
|
|
67
77
|
...options?.headers
|
|
68
78
|
};
|
|
69
79
|
params.body = JSON.stringify(body);
|
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import type { FileBody, FileObject } from './types';
|
|
2
2
|
type Fetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
3
3
|
export declare const resolveFetch: (customFetch?: Fetch) => Fetch;
|
|
4
|
+
/**
|
|
5
|
+
* Resolve the current origin at runtime.
|
|
6
|
+
*
|
|
7
|
+
* In a browser this is `window.location.origin`; in node/SSR there is no
|
|
8
|
+
* window so we fall back to an empty string, which yields a relative URL that
|
|
9
|
+
* the host fetch implementation resolves against its own base.
|
|
10
|
+
*/
|
|
11
|
+
export declare const getOrigin: () => string;
|
|
12
|
+
/**
|
|
13
|
+
* Build the storage runtime base url that all storage requests are issued
|
|
14
|
+
* against. Storage is authenticated via cookie session at
|
|
15
|
+
* `${origin}/app/${appId}/__runtime__/api/v1/storage`.
|
|
16
|
+
*/
|
|
17
|
+
export declare const getStorageBaseUrl: (appId?: string) => string;
|
|
4
18
|
export declare const resolveResponse: () => Promise<typeof Response>;
|
|
5
19
|
export declare const recursiveToCamel: (item: Record<string, unknown>) => unknown;
|
|
6
20
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/storage/libs/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAIpD,KAAK,KAAK,GAAG,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEjF,eAAO,MAAM,YAAY,GAAI,cAAc,KAAK,KAAG,KAQlD,CAAC;AAEF,eAAO,MAAM,eAAe,QAAa,OAAO,CAAC,OAAO,QAAQ,CAE/D,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,OAmBhE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,KAAG,OAa7C,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,MA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EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,KAC9C,UA8BH,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,UAAU,MAAM,WAMhD,CAAC;AAKF,eAAO,MAAM,oBAAoB,GAAI,KAAK,MAAM,YAE/C,CAAC"}
|
|
@@ -4,6 +4,11 @@ const resolveFetch = (customFetch)=>{
|
|
|
4
4
|
_fetch = customFetch ? customFetch : fetch;
|
|
5
5
|
return (input, init)=>_fetch(input, init);
|
|
6
6
|
};
|
|
7
|
+
const getOrigin = ()=>{
|
|
8
|
+
if ('undefined' != typeof window && window.location?.origin) return window.location.origin;
|
|
9
|
+
return '';
|
|
10
|
+
};
|
|
11
|
+
const getStorageBaseUrl = (appId)=>`${getOrigin()}/app/${appId ?? ''}/__runtime__/api/v1/storage`;
|
|
7
12
|
const resolveResponse = async ()=>Response;
|
|
8
13
|
const recursiveToCamel = (item)=>{
|
|
9
14
|
if (Array.isArray(item)) return item.map((el)=>recursiveToCamel(el));
|
|
@@ -67,4 +72,4 @@ const sanitizeFileName = (fileName)=>{
|
|
|
67
72
|
};
|
|
68
73
|
const VOLC_ENGINE_URL_REGEX = /^https:\/\/[\w-]+\.tos-cn-beijing\.volces\.com\/.+/;
|
|
69
74
|
const checkIsVolcEngineUrl = (url)=>VOLC_ENGINE_URL_REGEX.test(url);
|
|
70
|
-
export { checkIsVolcEngineUrl, getUpdateFileSize, isPlainObject, recursiveToCamel, resolveFetch, resolveResponse, sanitizeFileName, toValidExpiresIn, transformFilePayload };
|
|
75
|
+
export { checkIsVolcEngineUrl, getOrigin, getStorageBaseUrl, getUpdateFileSize, isPlainObject, recursiveToCamel, resolveFetch, resolveResponse, sanitizeFileName, toValidExpiresIn, transformFilePayload };
|
|
@@ -115,13 +115,12 @@ export interface FileOptionsV2 {
|
|
|
115
115
|
contentDisposition?: string;
|
|
116
116
|
}
|
|
117
117
|
export interface PreUploadBody {
|
|
118
|
-
|
|
119
|
-
file_size: string;
|
|
118
|
+
fileSize: string;
|
|
120
119
|
upsert?: boolean;
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
120
|
+
filePath?: string;
|
|
121
|
+
contentDisposition?: string;
|
|
122
|
+
contentType?: string;
|
|
123
|
+
fileName?: string;
|
|
125
124
|
}
|
|
126
125
|
export interface DestinationOptions {
|
|
127
126
|
destinationBucket?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/storage/libs/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,kBAAkB,GAAG,oBAAoB,GAAG;IACtD,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,WAAW,CAAC;AAElD,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,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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,
|
|
@@ -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,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read the `suda-csrf-token` value used to guard state-changing requests
|
|
3
|
+
* against CSRF.
|
|
4
|
+
*
|
|
5
|
+
* This intentionally re-implements the toolkit's `getCsrfToken` logic inside
|
|
6
|
+
* dataloom: dataloom is a low-level package and must not import toolkit
|
|
7
|
+
* (package boundary B1/B2). Keep the lookup order identical to toolkit:
|
|
8
|
+
* 1. read the `suda-csrf-token` cookie (URL-decoded)
|
|
9
|
+
* 2. fall back to `window.csrfToken` (set in fullstack mode)
|
|
10
|
+
* 3. return '' in non-browser environments (no document)
|
|
11
|
+
*
|
|
12
|
+
* @returns the csrf token, or an empty string when unavailable.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getCsrfToken(): string;
|
|
15
|
+
//# 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;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAqBrC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
function getCsrfToken() {
|
|
2
|
+
if ('undefined' == typeof document) return '';
|
|
3
|
+
const cookieName = 'suda-csrf-token';
|
|
4
|
+
const cookies = (document.cookie ?? '').split('; ');
|
|
5
|
+
for (const cookie of cookies){
|
|
6
|
+
const [name, value] = cookie.split('=');
|
|
7
|
+
if (name === cookieName && void 0 !== value) return decodeURIComponent(value);
|
|
8
|
+
}
|
|
9
|
+
if ('undefined' != typeof window) return window.csrfToken ?? '';
|
|
10
|
+
return '';
|
|
11
|
+
}
|
|
12
|
+
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 };
|