@bytescale/sdk 3.0.0-alpha.8 → 3.1.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 +388 -48
- package/dist/browser/cjs/main.js +705 -566
- package/dist/node/cjs/main.js +622 -240
- package/dist/node/esm/main.mjs +622 -240
- 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 -12
- package/dist/types/public/shared/UrlBuilderTypes.d.ts +0 -6
- 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 -4
- package/tests/UploadManager.test.ts +0 -7
- package/tests/UrlBuilder.test.ts +33 -27
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bytescale/sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Bytescale JavaScript SDK",
|
|
5
5
|
"author": "Bytescale <hello@bytescale.com> (https://www.bytescale.com)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,6 +13,10 @@
|
|
|
13
13
|
"require": "./dist/node/cjs/main.js",
|
|
14
14
|
"import": "./dist/node/esm/main.mjs"
|
|
15
15
|
},
|
|
16
|
+
"worker": {
|
|
17
|
+
"require": "./dist/worker/cjs/main.js",
|
|
18
|
+
"import": "./dist/worker/esm/main.mjs"
|
|
19
|
+
},
|
|
16
20
|
"default": "./dist/browser/cjs/main.js"
|
|
17
21
|
}
|
|
18
22
|
},
|
|
@@ -33,7 +37,7 @@
|
|
|
33
37
|
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
|
|
34
38
|
"typecheck": "tsc --noEmit",
|
|
35
39
|
"test": "NODE_OPTIONS=--experimental-vm-modules npx jest --runInBand --silent=false --verbose=false",
|
|
36
|
-
"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",
|
|
37
41
|
"postpack": "[ ! -f bytescale-sdk-*.tgz ] || mv bytescale-sdk-*.tgz bytescale-sdk.tgz",
|
|
38
42
|
"prepare": "husky install",
|
|
39
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",
|
|
@@ -87,7 +91,6 @@
|
|
|
87
91
|
"webpack": "5.75.0",
|
|
88
92
|
"webpack-cli": "4.10.0",
|
|
89
93
|
"webpack-node-externals": "2.5.2",
|
|
90
|
-
"webpack-shell-plugin-next": "2.3.1"
|
|
91
|
-
"wrapper-webpack-plugin": "2.2.2"
|
|
94
|
+
"webpack-shell-plugin-next": "2.3.1"
|
|
92
95
|
}
|
|
93
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,7 +34,7 @@ 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
40
|
options: { transformation: "preset", transformationPreset: "thumbnail" }
|
|
@@ -44,7 +44,7 @@ describe("UrlBuilder", () => {
|
|
|
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
50
|
options: { transformation: "preset", transformationPreset: "thumbnail", artifact: "/foo" }
|
|
@@ -54,7 +54,7 @@ describe("UrlBuilder", () => {
|
|
|
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
60
|
options: { transformation: "preset", transformationPreset: "thumbnail", artifact: "/foo", large: false }
|
|
@@ -64,7 +64,7 @@ describe("UrlBuilder", () => {
|
|
|
64
64
|
});
|
|
65
65
|
|
|
66
66
|
test("transformation preset with rewritten params", () => {
|
|
67
|
-
const actual =
|
|
67
|
+
const actual = UrlBuilder.url({
|
|
68
68
|
accountId: "1234abc",
|
|
69
69
|
filePath: "/example.jpg",
|
|
70
70
|
options: {
|
|
@@ -79,7 +79,7 @@ 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: {
|
|
@@ -91,7 +91,7 @@ describe("UrlBuilder", () => {
|
|
|
91
91
|
});
|
|
92
92
|
|
|
93
93
|
test("transformation API with one param", () => {
|
|
94
|
-
const actual =
|
|
94
|
+
const actual = UrlBuilder.url({
|
|
95
95
|
accountId: "1234abc",
|
|
96
96
|
filePath: "/example.jpg",
|
|
97
97
|
options: {
|
|
@@ -106,7 +106,7 @@ describe("UrlBuilder", () => {
|
|
|
106
106
|
});
|
|
107
107
|
|
|
108
108
|
test("transformation API with a mix of params", () => {
|
|
109
|
-
const actual =
|
|
109
|
+
const actual = UrlBuilder.url({
|
|
110
110
|
accountId: "1234abc",
|
|
111
111
|
filePath: "/example.jpg",
|
|
112
112
|
options: {
|
|
@@ -128,7 +128,7 @@ describe("UrlBuilder", () => {
|
|
|
128
128
|
});
|
|
129
129
|
|
|
130
130
|
test("elide null and undefined", () => {
|
|
131
|
-
const actual =
|
|
131
|
+
const actual = UrlBuilder.url({
|
|
132
132
|
accountId: "1234abc",
|
|
133
133
|
filePath: "/example.jpg",
|
|
134
134
|
options: {
|
|
@@ -145,19 +145,25 @@ describe("UrlBuilder", () => {
|
|
|
145
145
|
expect(actual).toEqual(expected);
|
|
146
146
|
});
|
|
147
147
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
+
// });
|
|
163
169
|
});
|