@bytescale/sdk 3.0.0-alpha.2 → 3.0.0-alpha.21
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 +391 -48
- package/dist/browser/cjs/main.js +723 -589
- package/dist/node/cjs/main.js +640 -263
- package/dist/node/esm/main.mjs +640 -263
- package/dist/types/index.d.ts +1 -1
- package/dist/types/private/AuthSessionState.d.ts +25 -8
- package/dist/types/private/EnvChecker.d.ts +1 -1
- package/dist/types/private/Mutex.d.ts +1 -1
- package/dist/types/private/StreamUtils.d.ts +1 -0
- package/dist/types/private/UploadManagerBase.d.ts +6 -1
- package/dist/types/private/UploadManagerBrowserWorkerBase.d.ts +19 -0
- package/dist/types/private/UploadManagerFetchUtils.d.ts +8 -0
- package/dist/types/private/model/AuthManagerInterface.d.ts +22 -5
- package/dist/types/private/model/AuthSession.d.ts +2 -2
- package/dist/types/private/model/OnPartProgress.d.ts +1 -1
- package/dist/types/private/model/UploadSourceProcessed.d.ts +6 -1
- package/dist/types/public/browser/AuthManagerBrowser.d.ts +11 -6
- package/dist/types/public/browser/UploadManagerBrowser.d.ts +3 -12
- package/dist/types/public/node/AuthManagerNode.d.ts +8 -3
- package/dist/types/public/shared/CommonTypes.d.ts +0 -1
- package/dist/types/public/shared/UrlBuilder.d.ts +10 -11
- package/dist/types/public/shared/UrlBuilderTypes.d.ts +65 -71
- package/dist/types/public/shared/generated/apis/FileApi.d.ts +104 -3
- package/dist/types/public/shared/generated/apis/FolderApi.d.ts +0 -3
- package/dist/types/public/shared/generated/apis/JobApi.d.ts +0 -3
- package/dist/types/public/shared/generated/apis/UploadApi.d.ts +6 -3
- package/dist/types/public/shared/generated/models/index.d.ts +5 -7
- package/dist/types/public/shared/generated/runtime.d.ts +7 -5
- package/dist/types/public/worker/UploadManagerWorker.d.ts +8 -0
- package/dist/types/public/worker/index.d.ts +2 -0
- package/dist/worker/cjs/main.js +2578 -0
- package/dist/worker/esm/main.mjs +2578 -0
- package/package.json +7 -8
- package/tests/UploadManager.test.ts +0 -7
- package/tests/UrlBuilder.test.ts +60 -59
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bytescale/sdk",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.21",
|
|
4
4
|
"description": "Bytescale JavaScript SDK",
|
|
5
5
|
"author": "Bytescale <hello@bytescale.com> (https://www.bytescale.com)",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"types": "dist/types/index.d.ts",
|
|
8
8
|
"main": "dist/node/cjs/main.js",
|
|
9
|
-
"module": "dist/node/esm/main.mjs",
|
|
10
9
|
"browser": "dist/browser/cjs/main.js",
|
|
11
10
|
"exports": {
|
|
12
11
|
".": {
|
|
@@ -14,10 +13,11 @@
|
|
|
14
13
|
"require": "./dist/node/cjs/main.js",
|
|
15
14
|
"import": "./dist/node/esm/main.mjs"
|
|
16
15
|
},
|
|
17
|
-
"
|
|
18
|
-
"require": "./dist/
|
|
16
|
+
"worker": {
|
|
17
|
+
"require": "./dist/worker/cjs/main.js",
|
|
18
|
+
"import": "./dist/worker/esm/main.mjs"
|
|
19
19
|
},
|
|
20
|
-
"default": "./dist/
|
|
20
|
+
"default": "./dist/browser/cjs/main.js"
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
23
|
"homepage": "https://www.bytescale.com/docs/sdks/javascript",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
|
|
38
38
|
"typecheck": "tsc --noEmit",
|
|
39
39
|
"test": "NODE_OPTIONS=--experimental-vm-modules npx jest --runInBand --silent=false --verbose=false",
|
|
40
|
-
"prepack": "npm run clean && webpack && tsc-alias && rm dist/types/index.
|
|
40
|
+
"prepack": "npm run clean && webpack && tsc-alias && rm dist/types/index.node.d.ts && rm dist/types/index.worker.d.ts && mv dist/types/index.browser.d.ts dist/types/index.d.ts",
|
|
41
41
|
"postpack": "[ ! -f bytescale-sdk-*.tgz ] || mv bytescale-sdk-*.tgz bytescale-sdk.tgz",
|
|
42
42
|
"prepare": "husky install",
|
|
43
43
|
"prepack:cdn": "npm run clean && webpack --config webpack.config.cdn.js && find dist -name \"*.ts\" -type f -delete && for f in dist/*.js; do cp -- \"$f\" \"${f%.js}\"; done",
|
|
@@ -91,7 +91,6 @@
|
|
|
91
91
|
"webpack": "5.75.0",
|
|
92
92
|
"webpack-cli": "4.10.0",
|
|
93
93
|
"webpack-node-externals": "2.5.2",
|
|
94
|
-
"webpack-shell-plugin-next": "2.3.1"
|
|
95
|
-
"wrapper-webpack-plugin": "2.2.2"
|
|
94
|
+
"webpack-shell-plugin-next": "2.3.1"
|
|
96
95
|
}
|
|
97
96
|
}
|
|
@@ -27,7 +27,6 @@ const largeFileSize = Math.pow(1024, 2) * 500; // 500MB
|
|
|
27
27
|
async function testStreamingUpload(expectedSize: number): Promise<void> {
|
|
28
28
|
const expectedData = await createRandomStreamFactory(expectedSize);
|
|
29
29
|
const uploadedFile = await uploadManager.upload({
|
|
30
|
-
accountId,
|
|
31
30
|
data: expectedData(),
|
|
32
31
|
size: expectedSize
|
|
33
32
|
});
|
|
@@ -56,7 +55,6 @@ describe("UploadManager", () => {
|
|
|
56
55
|
const expectedData = "";
|
|
57
56
|
const expectedSize = 0;
|
|
58
57
|
const uploadedFile = await uploadManager.upload({
|
|
59
|
-
accountId,
|
|
60
58
|
data: expectedData
|
|
61
59
|
});
|
|
62
60
|
const fileDetails = await fileApi.getFileDetails({ accountId, filePath: uploadedFile.filePath });
|
|
@@ -70,7 +68,6 @@ describe("UploadManager", () => {
|
|
|
70
68
|
const expectedData = "Example Data";
|
|
71
69
|
const expectedMime = "text/plain";
|
|
72
70
|
const uploadedFile = await uploadManager.upload({
|
|
73
|
-
accountId,
|
|
74
71
|
data: expectedData
|
|
75
72
|
});
|
|
76
73
|
const fileDetails = await fileApi.getFileDetails({ accountId, filePath: uploadedFile.filePath });
|
|
@@ -84,7 +81,6 @@ describe("UploadManager", () => {
|
|
|
84
81
|
const expectedData = JSON.stringify({ someValue: 42 });
|
|
85
82
|
const expectedMime = "application/json";
|
|
86
83
|
const uploadedFile = await uploadManager.upload({
|
|
87
|
-
accountId,
|
|
88
84
|
data: new buffer.Blob([expectedData], { type: expectedMime })
|
|
89
85
|
});
|
|
90
86
|
const fileDetails = await fileApi.getFileDetails({ accountId, filePath: uploadedFile.filePath });
|
|
@@ -98,7 +94,6 @@ describe("UploadManager", () => {
|
|
|
98
94
|
const expectedData = "Example Data";
|
|
99
95
|
const expectedMime = "text/plain";
|
|
100
96
|
const uploadedFile = await uploadManager.upload({
|
|
101
|
-
accountId,
|
|
102
97
|
data: Buffer.from(expectedData, "utf8"),
|
|
103
98
|
mime: expectedMime
|
|
104
99
|
});
|
|
@@ -113,7 +108,6 @@ describe("UploadManager", () => {
|
|
|
113
108
|
const expectedData = "Example Data";
|
|
114
109
|
const expectedMime = "application/octet-stream";
|
|
115
110
|
const uploadedFile = await uploadManager.upload({
|
|
116
|
-
accountId,
|
|
117
111
|
data: Buffer.from(expectedData, "utf8")
|
|
118
112
|
});
|
|
119
113
|
const fileDetails = await fileApi.getFileDetails({ accountId, filePath: uploadedFile.filePath });
|
|
@@ -129,7 +123,6 @@ describe("UploadManager", () => {
|
|
|
129
123
|
const expectedSize = largeFileSize;
|
|
130
124
|
const expectedData = await streamToBuffer((await createRandomStreamFactory(expectedSize))());
|
|
131
125
|
const uploadedFile = await uploadManager.upload({
|
|
132
|
-
accountId,
|
|
133
126
|
data: expectedData
|
|
134
127
|
});
|
|
135
128
|
const fileDetails = await fileApi.getFileDetails({ accountId, filePath: uploadedFile.filePath });
|
package/tests/UrlBuilder.test.ts
CHANGED
|
@@ -2,19 +2,19 @@ import { UrlBuilder } from "../src/public/shared";
|
|
|
2
2
|
|
|
3
3
|
describe("UrlBuilder", () => {
|
|
4
4
|
test("raw file without params", () => {
|
|
5
|
-
const actual =
|
|
5
|
+
const actual = UrlBuilder.url({ accountId: "1234abc", filePath: "/example.jpg" });
|
|
6
6
|
const expected = "https://upcdn.io/1234abc/raw/example.jpg";
|
|
7
7
|
expect(actual).toEqual(expected);
|
|
8
8
|
});
|
|
9
9
|
|
|
10
10
|
test("raw file with one param", () => {
|
|
11
|
-
const actual =
|
|
11
|
+
const actual = UrlBuilder.url({ accountId: "1234abc", filePath: "/example.jpg", options: { auth: true } });
|
|
12
12
|
const expected = "https://upcdn.io/1234abc/raw/example.jpg?auth=true";
|
|
13
13
|
expect(actual).toEqual(expected);
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
test("raw file with multiple params", () => {
|
|
17
|
-
const actual =
|
|
17
|
+
const actual = UrlBuilder.url({
|
|
18
18
|
accountId: "1234abc",
|
|
19
19
|
filePath: "/example.jpg",
|
|
20
20
|
options: { auth: true, cache: true, version: "42" }
|
|
@@ -24,7 +24,7 @@ describe("UrlBuilder", () => {
|
|
|
24
24
|
});
|
|
25
25
|
|
|
26
26
|
test("raw file with rewritten params", () => {
|
|
27
|
-
const actual =
|
|
27
|
+
const actual = UrlBuilder.url({
|
|
28
28
|
accountId: "1234abc",
|
|
29
29
|
filePath: "/example.jpg",
|
|
30
30
|
options: { auth: true, cache: true, cacheTtl: 100 } // cacheTtl is rewritten to cache_ttl
|
|
@@ -34,44 +34,44 @@ describe("UrlBuilder", () => {
|
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
test("transformation preset without params", () => {
|
|
37
|
-
const actual =
|
|
37
|
+
const actual = UrlBuilder.url({
|
|
38
38
|
accountId: "1234abc",
|
|
39
39
|
filePath: "/example.jpg",
|
|
40
|
-
options: { transformation:
|
|
40
|
+
options: { transformation: "preset", transformationPreset: "thumbnail" }
|
|
41
41
|
});
|
|
42
42
|
const expected = "https://upcdn.io/1234abc/thumbnail/example.jpg";
|
|
43
43
|
expect(actual).toEqual(expected);
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
test("transformation preset with one param", () => {
|
|
47
|
-
const actual =
|
|
47
|
+
const actual = UrlBuilder.url({
|
|
48
48
|
accountId: "1234abc",
|
|
49
49
|
filePath: "/example.jpg",
|
|
50
|
-
options: { transformation:
|
|
50
|
+
options: { transformation: "preset", transformationPreset: "thumbnail", artifact: "/foo" }
|
|
51
51
|
});
|
|
52
52
|
const expected = "https://upcdn.io/1234abc/thumbnail/example.jpg?artifact=%2Ffoo";
|
|
53
53
|
expect(actual).toEqual(expected);
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
test("transformation preset with multiple params", () => {
|
|
57
|
-
const actual =
|
|
57
|
+
const actual = UrlBuilder.url({
|
|
58
58
|
accountId: "1234abc",
|
|
59
59
|
filePath: "/example.jpg",
|
|
60
|
-
options: {
|
|
61
|
-
transformation: { type: "preset", preset: "thumbnail", params: { large: false, artifact: "/foo" } }
|
|
62
|
-
}
|
|
60
|
+
options: { transformation: "preset", transformationPreset: "thumbnail", artifact: "/foo", large: false }
|
|
63
61
|
});
|
|
64
62
|
const expected = "https://upcdn.io/1234abc/thumbnail/example.jpg?large=false&artifact=%2Ffoo";
|
|
65
63
|
expect(actual).toEqual(expected);
|
|
66
64
|
});
|
|
67
65
|
|
|
68
66
|
test("transformation preset with rewritten params", () => {
|
|
69
|
-
const actual =
|
|
67
|
+
const actual = UrlBuilder.url({
|
|
70
68
|
accountId: "1234abc",
|
|
71
69
|
filePath: "/example.jpg",
|
|
72
70
|
options: {
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
transformation: "preset",
|
|
72
|
+
transformationPreset: "thumbnail",
|
|
73
|
+
artifact: "/foo",
|
|
74
|
+
cachePermanently: false
|
|
75
75
|
}
|
|
76
76
|
});
|
|
77
77
|
const expected = "https://upcdn.io/1234abc/thumbnail/example.jpg?cache_perm=false&artifact=%2Ffoo";
|
|
@@ -79,13 +79,11 @@ describe("UrlBuilder", () => {
|
|
|
79
79
|
});
|
|
80
80
|
|
|
81
81
|
test("transformation API without params", () => {
|
|
82
|
-
const actual =
|
|
82
|
+
const actual = UrlBuilder.url({
|
|
83
83
|
accountId: "1234abc",
|
|
84
84
|
filePath: "/example.jpg",
|
|
85
85
|
options: {
|
|
86
|
-
transformation:
|
|
87
|
-
type: "image"
|
|
88
|
-
}
|
|
86
|
+
transformation: "image"
|
|
89
87
|
}
|
|
90
88
|
});
|
|
91
89
|
const expected = "https://upcdn.io/1234abc/image/example.jpg";
|
|
@@ -93,15 +91,13 @@ describe("UrlBuilder", () => {
|
|
|
93
91
|
});
|
|
94
92
|
|
|
95
93
|
test("transformation API with one param", () => {
|
|
96
|
-
const actual =
|
|
94
|
+
const actual = UrlBuilder.url({
|
|
97
95
|
accountId: "1234abc",
|
|
98
96
|
filePath: "/example.jpg",
|
|
99
97
|
options: {
|
|
100
|
-
transformation:
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
w: 42
|
|
104
|
-
}
|
|
98
|
+
transformation: "image",
|
|
99
|
+
transformationParams: {
|
|
100
|
+
w: 42
|
|
105
101
|
}
|
|
106
102
|
}
|
|
107
103
|
});
|
|
@@ -110,59 +106,64 @@ describe("UrlBuilder", () => {
|
|
|
110
106
|
});
|
|
111
107
|
|
|
112
108
|
test("transformation API with a mix of params", () => {
|
|
113
|
-
const actual =
|
|
109
|
+
const actual = UrlBuilder.url({
|
|
114
110
|
accountId: "1234abc",
|
|
115
111
|
filePath: "/example.jpg",
|
|
116
112
|
options: {
|
|
117
|
-
transformation:
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
h: 50
|
|
122
|
-
}
|
|
113
|
+
transformation: "image",
|
|
114
|
+
transformationParams: {
|
|
115
|
+
w: 42,
|
|
116
|
+
h: 50
|
|
123
117
|
},
|
|
118
|
+
cachePermanently: "auto",
|
|
119
|
+
artifact: "/foo",
|
|
120
|
+
large: true,
|
|
121
|
+
version: "50",
|
|
124
122
|
auth: true
|
|
125
123
|
}
|
|
126
124
|
});
|
|
127
|
-
const expected =
|
|
125
|
+
const expected =
|
|
126
|
+
"https://upcdn.io/1234abc/image/example.jpg?w=42&h=50&auth=true&version=50&cache_perm=auto&large=true&artifact=%2Ffoo";
|
|
128
127
|
expect(actual).toEqual(expected);
|
|
129
128
|
});
|
|
130
129
|
|
|
131
130
|
test("elide null and undefined", () => {
|
|
132
|
-
const actual =
|
|
131
|
+
const actual = UrlBuilder.url({
|
|
133
132
|
accountId: "1234abc",
|
|
134
133
|
filePath: "/example.jpg",
|
|
135
134
|
options: {
|
|
136
|
-
transformation:
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
r: 52
|
|
142
|
-
}
|
|
135
|
+
transformation: "image",
|
|
136
|
+
transformationParams: {
|
|
137
|
+
w: undefined,
|
|
138
|
+
h: null,
|
|
139
|
+
r: 52
|
|
143
140
|
},
|
|
144
141
|
auth: true
|
|
145
142
|
}
|
|
146
143
|
});
|
|
147
|
-
const expected = "https://upcdn.io/1234abc/image/example.jpg?auth=true
|
|
144
|
+
const expected = "https://upcdn.io/1234abc/image/example.jpg?r=52&auth=true";
|
|
148
145
|
expect(actual).toEqual(expected);
|
|
149
146
|
});
|
|
150
147
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
148
|
+
// In the future, after we release our new domain structure (byte.cm), we will offer these 2 params:
|
|
149
|
+
// - subdomain
|
|
150
|
+
// - domain
|
|
151
|
+
// If the user specifies either of these, we use the new syntax, which excludes the account ID prefix.
|
|
152
|
+
// We will also automatically use their default subdomain (which is a function of their account ID) if unspecified.
|
|
153
|
+
// This means customers on legacy custom CNAMEs are not (and will not) be supported by the UrlBuilder.
|
|
154
|
+
// test("custom CNAME", () => {
|
|
155
|
+
// const actual = new UrlBuilder({ cdnUrl: "https://example.com" }).url({
|
|
156
|
+
// accountId: "1234abc",
|
|
157
|
+
// filePath: "/example.jpg",
|
|
158
|
+
// options: {
|
|
159
|
+
// transformation: "image",
|
|
160
|
+
// transformationParams: {
|
|
161
|
+
// w: 42,
|
|
162
|
+
// h: 50
|
|
163
|
+
// }
|
|
164
|
+
// }
|
|
165
|
+
// });
|
|
166
|
+
// const expected = "https://example.com/1234abc/image/example.jpg?w=42&h=50";
|
|
167
|
+
// expect(actual).toEqual(expected);
|
|
168
|
+
// });
|
|
168
169
|
});
|