@bytescale/sdk 3.0.0-alpha.15 → 3.0.0-alpha.17
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 +11 -5
- package/dist/browser/cjs/main.js +26 -26
- package/dist/node/cjs/main.js +25 -25
- package/dist/node/esm/main.mjs +25 -25
- package/dist/types/index.d.ts +1 -1
- package/dist/types/public/shared/UrlBuilder.d.ts +10 -12
- package/dist/types/public/shared/UrlBuilderTypes.d.ts +0 -6
- package/dist/worker/cjs/main.js +26 -26
- package/dist/worker/esm/main.mjs +26 -26
- package/package.json +2 -2
- package/tests/UrlBuilder.test.ts +33 -27
- package/dist/browser/esm/main.mjs +0 -2793
- package/dist/types/index.worker.d.ts +0 -2
package/README.md
CHANGED
|
@@ -110,6 +110,9 @@ uploadManager
|
|
|
110
110
|
// Required if 'data' is a stream, buffer, or string.
|
|
111
111
|
originalFileName: "my_file.txt"
|
|
112
112
|
|
|
113
|
+
// Reports progress: bytesTotal, bytesSent, progress.
|
|
114
|
+
// onProgress: ({ progress }) => console.log(progress),
|
|
115
|
+
|
|
113
116
|
// Controls multipart upload concurrency. Ignored if 'data' is a stream.
|
|
114
117
|
// maxConcurrentUploadParts: 4,
|
|
115
118
|
|
|
@@ -188,6 +191,9 @@ uploadManager
|
|
|
188
191
|
// Required if 'data' is a stream, buffer, or string. (Not required for DOM file inputs or blobs.)
|
|
189
192
|
// originalFileName: "my_file.txt",
|
|
190
193
|
|
|
194
|
+
// Reports progress: bytesTotal, bytesSent, progress.
|
|
195
|
+
// onProgress: ({ progress }) => console.log(progress),
|
|
196
|
+
|
|
191
197
|
// Controls multipart upload concurrency. Ignored if 'data' is a stream.
|
|
192
198
|
// maxConcurrentUploadParts: 4,
|
|
193
199
|
|
|
@@ -396,7 +402,7 @@ To get the URL for the uploaded image `/example.jpg` in its original form, use t
|
|
|
396
402
|
|
|
397
403
|
```javascript
|
|
398
404
|
// Returns: "https://upcdn.io/1234abc/raw/example.jpg"
|
|
399
|
-
|
|
405
|
+
UrlBuilder.url({
|
|
400
406
|
accountId: "1234abc",
|
|
401
407
|
filePath: "/example.jpg"
|
|
402
408
|
});
|
|
@@ -408,7 +414,7 @@ To resize the uploaded image `/example.jpg` to 800x600, use the following params
|
|
|
408
414
|
|
|
409
415
|
```javascript
|
|
410
416
|
// Returns: "https://upcdn.io/1234abc/image/example.jpg?w=800&h=600"
|
|
411
|
-
|
|
417
|
+
UrlBuilder.url({
|
|
412
418
|
accountId: "1234abc",
|
|
413
419
|
filePath: "/example.jpg",
|
|
414
420
|
options: {
|
|
@@ -429,7 +435,7 @@ To transcode the uploaded video `/example.mov` to MP4/H.264 in HD, use the follo
|
|
|
429
435
|
|
|
430
436
|
```javascript
|
|
431
437
|
// Returns: "https://upcdn.io/1234abc/video/example.mov?f=mp4-h264&h=1080"
|
|
432
|
-
|
|
438
|
+
UrlBuilder.url({
|
|
433
439
|
accountId: "1234abc",
|
|
434
440
|
filePath: "/example.mov",
|
|
435
441
|
options: {
|
|
@@ -450,7 +456,7 @@ To transcode the uploaded audio `/example.wav` to AAC in 192kbps, use the follow
|
|
|
450
456
|
|
|
451
457
|
```javascript
|
|
452
458
|
// Returns: "https://upcdn.io/1234abc/audio/example.wav?f=aac&br=192"
|
|
453
|
-
|
|
459
|
+
UrlBuilder.url({
|
|
454
460
|
accountId: "1234abc",
|
|
455
461
|
filePath: "/example.wav",
|
|
456
462
|
options: {
|
|
@@ -471,7 +477,7 @@ To extract the file `document.docx` from the uploaded ZIP file `/example.zip`, u
|
|
|
471
477
|
|
|
472
478
|
```javascript
|
|
473
479
|
// Returns: "https://upcdn.io/1234abc/archive/example.zip?m=extract&artifact=/document.docx"
|
|
474
|
-
|
|
480
|
+
UrlBuilder.url({
|
|
475
481
|
accountId: "1234abc",
|
|
476
482
|
filePath: "/example.zip",
|
|
477
483
|
options: {
|
package/dist/browser/cjs/main.js
CHANGED
|
@@ -1686,33 +1686,32 @@ function UrlBuilder_toPrimitive(input, hint) { if (UrlBuilder_typeof(input) !==
|
|
|
1686
1686
|
|
|
1687
1687
|
|
|
1688
1688
|
var UrlBuilder = /*#__PURE__*/function () {
|
|
1689
|
-
function UrlBuilder(
|
|
1689
|
+
function UrlBuilder() {
|
|
1690
1690
|
UrlBuilder_classCallCheck(this, UrlBuilder);
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
}
|
|
1694
|
-
/**
|
|
1695
|
-
* Builds a URL to either a raw file or a transformed file.
|
|
1696
|
-
*
|
|
1697
|
-
* Example 1) Getting a publicly-accessible raw file URL:
|
|
1698
|
-
*
|
|
1699
|
-
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg" })
|
|
1700
|
-
*
|
|
1701
|
-
* Example 2) Getting a publicly-accessible image URL, resized to 500x500:
|
|
1702
|
-
*
|
|
1703
|
-
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } } } })
|
|
1704
|
-
*
|
|
1705
|
-
* Example 3) Getting a privately-accessible image URL, resized to 500x500 (requires 'AuthManager.beginAuthSession' to be called before accessing the URL):
|
|
1706
|
-
*
|
|
1707
|
-
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } }, auth: true } })
|
|
1708
|
-
*
|
|
1709
|
-
* Example 4) Getting a publicly-accessible image URL, resized using a transformation preset called "thumbnail" that was created manually in the Bytescale Dashboard:
|
|
1710
|
-
*
|
|
1711
|
-
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "preset", preset: "thumbnail" } } })
|
|
1712
|
-
*/
|
|
1713
|
-
UrlBuilder_createClass(UrlBuilder, [{
|
|
1691
|
+
}
|
|
1692
|
+
UrlBuilder_createClass(UrlBuilder, null, [{
|
|
1714
1693
|
key: "url",
|
|
1715
|
-
value:
|
|
1694
|
+
value:
|
|
1695
|
+
/**
|
|
1696
|
+
* Builds a URL to either a raw file or a transformed file.
|
|
1697
|
+
*
|
|
1698
|
+
* Example 1) Getting a publicly-accessible raw file URL:
|
|
1699
|
+
*
|
|
1700
|
+
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg" })
|
|
1701
|
+
*
|
|
1702
|
+
* Example 2) Getting a publicly-accessible image URL, resized to 500x500:
|
|
1703
|
+
*
|
|
1704
|
+
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } } } })
|
|
1705
|
+
*
|
|
1706
|
+
* Example 3) Getting a privately-accessible image URL, resized to 500x500 (requires 'AuthManager.beginAuthSession' to be called before accessing the URL):
|
|
1707
|
+
*
|
|
1708
|
+
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } }, auth: true } })
|
|
1709
|
+
*
|
|
1710
|
+
* Example 4) Getting a publicly-accessible image URL, resized using a transformation preset called "thumbnail" that was created manually in the Bytescale Dashboard:
|
|
1711
|
+
*
|
|
1712
|
+
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "preset", preset: "thumbnail" } } })
|
|
1713
|
+
*/
|
|
1714
|
+
function url(params) {
|
|
1716
1715
|
var _a;
|
|
1717
1716
|
return ((_a = params.options) === null || _a === void 0 ? void 0 : _a.transformation) === undefined ? this.raw(params) : this.transformation(params, params.options);
|
|
1718
1717
|
}
|
|
@@ -1738,7 +1737,8 @@ var UrlBuilder = /*#__PURE__*/function () {
|
|
|
1738
1737
|
}, {
|
|
1739
1738
|
key: "getBaseUrl",
|
|
1740
1739
|
value: function getBaseUrl(params, prefix) {
|
|
1741
|
-
|
|
1740
|
+
var cdnUrl = BytescaleApiClientConfigUtils.defaultCdnUrl;
|
|
1741
|
+
return "".concat(cdnUrl, "/").concat(params.accountId, "/").concat(prefix).concat(params.filePath);
|
|
1742
1742
|
}
|
|
1743
1743
|
}, {
|
|
1744
1744
|
key: "getCommonTransformationQueryParams",
|
package/dist/node/cjs/main.js
CHANGED
|
@@ -1686,33 +1686,32 @@ function UrlBuilder_toPrimitive(input, hint) { if (UrlBuilder_typeof(input) !==
|
|
|
1686
1686
|
|
|
1687
1687
|
|
|
1688
1688
|
var UrlBuilder = /*#__PURE__*/function () {
|
|
1689
|
-
function UrlBuilder(
|
|
1689
|
+
function UrlBuilder() {
|
|
1690
1690
|
UrlBuilder_classCallCheck(this, UrlBuilder);
|
|
1691
|
-
var _a;
|
|
1692
|
-
this.cdnUrl = (_a = config === null || config === void 0 ? void 0 : config.cdnUrl) !== null && _a !== void 0 ? _a : BytescaleApiClientConfigUtils.defaultCdnUrl;
|
|
1693
1691
|
}
|
|
1694
|
-
|
|
1695
|
-
* Builds a URL to either a raw file or a transformed file.
|
|
1696
|
-
*
|
|
1697
|
-
* Example 1) Getting a publicly-accessible raw file URL:
|
|
1698
|
-
*
|
|
1699
|
-
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg" })
|
|
1700
|
-
*
|
|
1701
|
-
* Example 2) Getting a publicly-accessible image URL, resized to 500x500:
|
|
1702
|
-
*
|
|
1703
|
-
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } } } })
|
|
1704
|
-
*
|
|
1705
|
-
* Example 3) Getting a privately-accessible image URL, resized to 500x500 (requires 'AuthManager.beginAuthSession' to be called before accessing the URL):
|
|
1706
|
-
*
|
|
1707
|
-
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } }, auth: true } })
|
|
1708
|
-
*
|
|
1709
|
-
* Example 4) Getting a publicly-accessible image URL, resized using a transformation preset called "thumbnail" that was created manually in the Bytescale Dashboard:
|
|
1710
|
-
*
|
|
1711
|
-
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "preset", preset: "thumbnail" } } })
|
|
1712
|
-
*/
|
|
1713
|
-
UrlBuilder_createClass(UrlBuilder, [{
|
|
1692
|
+
UrlBuilder_createClass(UrlBuilder, null, [{
|
|
1714
1693
|
key: "url",
|
|
1715
|
-
value:
|
|
1694
|
+
value:
|
|
1695
|
+
/**
|
|
1696
|
+
* Builds a URL to either a raw file or a transformed file.
|
|
1697
|
+
*
|
|
1698
|
+
* Example 1) Getting a publicly-accessible raw file URL:
|
|
1699
|
+
*
|
|
1700
|
+
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg" })
|
|
1701
|
+
*
|
|
1702
|
+
* Example 2) Getting a publicly-accessible image URL, resized to 500x500:
|
|
1703
|
+
*
|
|
1704
|
+
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } } } })
|
|
1705
|
+
*
|
|
1706
|
+
* Example 3) Getting a privately-accessible image URL, resized to 500x500 (requires 'AuthManager.beginAuthSession' to be called before accessing the URL):
|
|
1707
|
+
*
|
|
1708
|
+
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } }, auth: true } })
|
|
1709
|
+
*
|
|
1710
|
+
* Example 4) Getting a publicly-accessible image URL, resized using a transformation preset called "thumbnail" that was created manually in the Bytescale Dashboard:
|
|
1711
|
+
*
|
|
1712
|
+
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "preset", preset: "thumbnail" } } })
|
|
1713
|
+
*/
|
|
1714
|
+
function url(params) {
|
|
1716
1715
|
var _a;
|
|
1717
1716
|
return ((_a = params.options) === null || _a === void 0 ? void 0 : _a.transformation) === undefined ? this.raw(params) : this.transformation(params, params.options);
|
|
1718
1717
|
}
|
|
@@ -1738,7 +1737,8 @@ var UrlBuilder = /*#__PURE__*/function () {
|
|
|
1738
1737
|
}, {
|
|
1739
1738
|
key: "getBaseUrl",
|
|
1740
1739
|
value: function getBaseUrl(params, prefix) {
|
|
1741
|
-
|
|
1740
|
+
var cdnUrl = BytescaleApiClientConfigUtils.defaultCdnUrl;
|
|
1741
|
+
return "".concat(cdnUrl, "/").concat(params.accountId, "/").concat(prefix).concat(params.filePath);
|
|
1742
1742
|
}
|
|
1743
1743
|
}, {
|
|
1744
1744
|
key: "getCommonTransformationQueryParams",
|
package/dist/node/esm/main.mjs
CHANGED
|
@@ -1673,33 +1673,32 @@ function UrlBuilder_toPrimitive(input, hint) { if (UrlBuilder_typeof(input) !==
|
|
|
1673
1673
|
|
|
1674
1674
|
|
|
1675
1675
|
var UrlBuilder = /*#__PURE__*/function () {
|
|
1676
|
-
function UrlBuilder(
|
|
1676
|
+
function UrlBuilder() {
|
|
1677
1677
|
UrlBuilder_classCallCheck(this, UrlBuilder);
|
|
1678
|
-
var _a;
|
|
1679
|
-
this.cdnUrl = (_a = config === null || config === void 0 ? void 0 : config.cdnUrl) !== null && _a !== void 0 ? _a : BytescaleApiClientConfigUtils.defaultCdnUrl;
|
|
1680
1678
|
}
|
|
1681
|
-
|
|
1682
|
-
* Builds a URL to either a raw file or a transformed file.
|
|
1683
|
-
*
|
|
1684
|
-
* Example 1) Getting a publicly-accessible raw file URL:
|
|
1685
|
-
*
|
|
1686
|
-
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg" })
|
|
1687
|
-
*
|
|
1688
|
-
* Example 2) Getting a publicly-accessible image URL, resized to 500x500:
|
|
1689
|
-
*
|
|
1690
|
-
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } } } })
|
|
1691
|
-
*
|
|
1692
|
-
* Example 3) Getting a privately-accessible image URL, resized to 500x500 (requires 'AuthManager.beginAuthSession' to be called before accessing the URL):
|
|
1693
|
-
*
|
|
1694
|
-
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } }, auth: true } })
|
|
1695
|
-
*
|
|
1696
|
-
* Example 4) Getting a publicly-accessible image URL, resized using a transformation preset called "thumbnail" that was created manually in the Bytescale Dashboard:
|
|
1697
|
-
*
|
|
1698
|
-
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "preset", preset: "thumbnail" } } })
|
|
1699
|
-
*/
|
|
1700
|
-
UrlBuilder_createClass(UrlBuilder, [{
|
|
1679
|
+
UrlBuilder_createClass(UrlBuilder, null, [{
|
|
1701
1680
|
key: "url",
|
|
1702
|
-
value:
|
|
1681
|
+
value:
|
|
1682
|
+
/**
|
|
1683
|
+
* Builds a URL to either a raw file or a transformed file.
|
|
1684
|
+
*
|
|
1685
|
+
* Example 1) Getting a publicly-accessible raw file URL:
|
|
1686
|
+
*
|
|
1687
|
+
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg" })
|
|
1688
|
+
*
|
|
1689
|
+
* Example 2) Getting a publicly-accessible image URL, resized to 500x500:
|
|
1690
|
+
*
|
|
1691
|
+
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } } } })
|
|
1692
|
+
*
|
|
1693
|
+
* Example 3) Getting a privately-accessible image URL, resized to 500x500 (requires 'AuthManager.beginAuthSession' to be called before accessing the URL):
|
|
1694
|
+
*
|
|
1695
|
+
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } }, auth: true } })
|
|
1696
|
+
*
|
|
1697
|
+
* Example 4) Getting a publicly-accessible image URL, resized using a transformation preset called "thumbnail" that was created manually in the Bytescale Dashboard:
|
|
1698
|
+
*
|
|
1699
|
+
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "preset", preset: "thumbnail" } } })
|
|
1700
|
+
*/
|
|
1701
|
+
function url(params) {
|
|
1703
1702
|
var _a;
|
|
1704
1703
|
return ((_a = params.options) === null || _a === void 0 ? void 0 : _a.transformation) === undefined ? this.raw(params) : this.transformation(params, params.options);
|
|
1705
1704
|
}
|
|
@@ -1725,7 +1724,8 @@ var UrlBuilder = /*#__PURE__*/function () {
|
|
|
1725
1724
|
}, {
|
|
1726
1725
|
key: "getBaseUrl",
|
|
1727
1726
|
value: function getBaseUrl(params, prefix) {
|
|
1728
|
-
|
|
1727
|
+
var cdnUrl = BytescaleApiClientConfigUtils.defaultCdnUrl;
|
|
1728
|
+
return "".concat(cdnUrl, "/").concat(params.accountId, "/").concat(prefix).concat(params.filePath);
|
|
1729
1729
|
}
|
|
1730
1730
|
}, {
|
|
1731
1731
|
key: "getCommonTransformationQueryParams",
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from "./public/shared";
|
|
2
|
-
export * from "./public/
|
|
2
|
+
export * from "./public/browser";
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UrlBuilderParams } from "./UrlBuilderTypes";
|
|
2
2
|
export declare class UrlBuilder {
|
|
3
|
-
private readonly cdnUrl;
|
|
4
|
-
constructor(config?: UrlBuilderConfig);
|
|
5
3
|
/**
|
|
6
4
|
* Builds a URL to either a raw file or a transformed file.
|
|
7
5
|
*
|
|
@@ -21,13 +19,13 @@ export declare class UrlBuilder {
|
|
|
21
19
|
*
|
|
22
20
|
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "preset", preset: "thumbnail" } } })
|
|
23
21
|
*/
|
|
24
|
-
url(params: UrlBuilderParams): string;
|
|
25
|
-
private raw;
|
|
26
|
-
private transformation;
|
|
27
|
-
private getBaseUrl;
|
|
28
|
-
private getCommonTransformationQueryParams;
|
|
29
|
-
private getCommonQueryParams;
|
|
30
|
-
private makeQueryParams;
|
|
31
|
-
private getTransformationParams;
|
|
32
|
-
private addQueryParams;
|
|
22
|
+
static url(params: UrlBuilderParams): string;
|
|
23
|
+
private static raw;
|
|
24
|
+
private static transformation;
|
|
25
|
+
private static getBaseUrl;
|
|
26
|
+
private static getCommonTransformationQueryParams;
|
|
27
|
+
private static getCommonQueryParams;
|
|
28
|
+
private static makeQueryParams;
|
|
29
|
+
private static getTransformationParams;
|
|
30
|
+
private static addQueryParams;
|
|
33
31
|
}
|
|
@@ -4,12 +4,6 @@
|
|
|
4
4
|
export declare const UrlBuilderTypesNoOp = false;
|
|
5
5
|
export declare type ParameterGroup = Record<string, string | number | boolean | undefined | null>;
|
|
6
6
|
export declare type KeyValuePair = [string, string];
|
|
7
|
-
export interface UrlBuilderConfig {
|
|
8
|
-
/**
|
|
9
|
-
* The base URL of the Bytescale CDN.
|
|
10
|
-
*/
|
|
11
|
-
cdnUrl?: string;
|
|
12
|
-
}
|
|
13
7
|
export interface UrlBuilderParams {
|
|
14
8
|
/**
|
|
15
9
|
* The account that manages the file.
|
package/dist/worker/cjs/main.js
CHANGED
|
@@ -1686,33 +1686,32 @@ function UrlBuilder_toPrimitive(input, hint) { if (UrlBuilder_typeof(input) !==
|
|
|
1686
1686
|
|
|
1687
1687
|
|
|
1688
1688
|
var UrlBuilder = /*#__PURE__*/function () {
|
|
1689
|
-
function UrlBuilder(
|
|
1689
|
+
function UrlBuilder() {
|
|
1690
1690
|
UrlBuilder_classCallCheck(this, UrlBuilder);
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
}
|
|
1694
|
-
/**
|
|
1695
|
-
* Builds a URL to either a raw file or a transformed file.
|
|
1696
|
-
*
|
|
1697
|
-
* Example 1) Getting a publicly-accessible raw file URL:
|
|
1698
|
-
*
|
|
1699
|
-
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg" })
|
|
1700
|
-
*
|
|
1701
|
-
* Example 2) Getting a publicly-accessible image URL, resized to 500x500:
|
|
1702
|
-
*
|
|
1703
|
-
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } } } })
|
|
1704
|
-
*
|
|
1705
|
-
* Example 3) Getting a privately-accessible image URL, resized to 500x500 (requires 'AuthManager.beginAuthSession' to be called before accessing the URL):
|
|
1706
|
-
*
|
|
1707
|
-
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } }, auth: true } })
|
|
1708
|
-
*
|
|
1709
|
-
* Example 4) Getting a publicly-accessible image URL, resized using a transformation preset called "thumbnail" that was created manually in the Bytescale Dashboard:
|
|
1710
|
-
*
|
|
1711
|
-
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "preset", preset: "thumbnail" } } })
|
|
1712
|
-
*/
|
|
1713
|
-
UrlBuilder_createClass(UrlBuilder, [{
|
|
1691
|
+
}
|
|
1692
|
+
UrlBuilder_createClass(UrlBuilder, null, [{
|
|
1714
1693
|
key: "url",
|
|
1715
|
-
value:
|
|
1694
|
+
value:
|
|
1695
|
+
/**
|
|
1696
|
+
* Builds a URL to either a raw file or a transformed file.
|
|
1697
|
+
*
|
|
1698
|
+
* Example 1) Getting a publicly-accessible raw file URL:
|
|
1699
|
+
*
|
|
1700
|
+
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg" })
|
|
1701
|
+
*
|
|
1702
|
+
* Example 2) Getting a publicly-accessible image URL, resized to 500x500:
|
|
1703
|
+
*
|
|
1704
|
+
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } } } })
|
|
1705
|
+
*
|
|
1706
|
+
* Example 3) Getting a privately-accessible image URL, resized to 500x500 (requires 'AuthManager.beginAuthSession' to be called before accessing the URL):
|
|
1707
|
+
*
|
|
1708
|
+
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } }, auth: true } })
|
|
1709
|
+
*
|
|
1710
|
+
* Example 4) Getting a publicly-accessible image URL, resized using a transformation preset called "thumbnail" that was created manually in the Bytescale Dashboard:
|
|
1711
|
+
*
|
|
1712
|
+
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "preset", preset: "thumbnail" } } })
|
|
1713
|
+
*/
|
|
1714
|
+
function url(params) {
|
|
1716
1715
|
var _a;
|
|
1717
1716
|
return ((_a = params.options) === null || _a === void 0 ? void 0 : _a.transformation) === undefined ? this.raw(params) : this.transformation(params, params.options);
|
|
1718
1717
|
}
|
|
@@ -1738,7 +1737,8 @@ var UrlBuilder = /*#__PURE__*/function () {
|
|
|
1738
1737
|
}, {
|
|
1739
1738
|
key: "getBaseUrl",
|
|
1740
1739
|
value: function getBaseUrl(params, prefix) {
|
|
1741
|
-
|
|
1740
|
+
var cdnUrl = BytescaleApiClientConfigUtils.defaultCdnUrl;
|
|
1741
|
+
return "".concat(cdnUrl, "/").concat(params.accountId, "/").concat(prefix).concat(params.filePath);
|
|
1742
1742
|
}
|
|
1743
1743
|
}, {
|
|
1744
1744
|
key: "getCommonTransformationQueryParams",
|
package/dist/worker/esm/main.mjs
CHANGED
|
@@ -1671,33 +1671,32 @@ function UrlBuilder_toPrimitive(input, hint) { if (UrlBuilder_typeof(input) !==
|
|
|
1671
1671
|
|
|
1672
1672
|
|
|
1673
1673
|
var UrlBuilder = /*#__PURE__*/function () {
|
|
1674
|
-
function UrlBuilder(
|
|
1674
|
+
function UrlBuilder() {
|
|
1675
1675
|
UrlBuilder_classCallCheck(this, UrlBuilder);
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
}
|
|
1679
|
-
/**
|
|
1680
|
-
* Builds a URL to either a raw file or a transformed file.
|
|
1681
|
-
*
|
|
1682
|
-
* Example 1) Getting a publicly-accessible raw file URL:
|
|
1683
|
-
*
|
|
1684
|
-
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg" })
|
|
1685
|
-
*
|
|
1686
|
-
* Example 2) Getting a publicly-accessible image URL, resized to 500x500:
|
|
1687
|
-
*
|
|
1688
|
-
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } } } })
|
|
1689
|
-
*
|
|
1690
|
-
* Example 3) Getting a privately-accessible image URL, resized to 500x500 (requires 'AuthManager.beginAuthSession' to be called before accessing the URL):
|
|
1691
|
-
*
|
|
1692
|
-
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } }, auth: true } })
|
|
1693
|
-
*
|
|
1694
|
-
* Example 4) Getting a publicly-accessible image URL, resized using a transformation preset called "thumbnail" that was created manually in the Bytescale Dashboard:
|
|
1695
|
-
*
|
|
1696
|
-
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "preset", preset: "thumbnail" } } })
|
|
1697
|
-
*/
|
|
1698
|
-
UrlBuilder_createClass(UrlBuilder, [{
|
|
1676
|
+
}
|
|
1677
|
+
UrlBuilder_createClass(UrlBuilder, null, [{
|
|
1699
1678
|
key: "url",
|
|
1700
|
-
value:
|
|
1679
|
+
value:
|
|
1680
|
+
/**
|
|
1681
|
+
* Builds a URL to either a raw file or a transformed file.
|
|
1682
|
+
*
|
|
1683
|
+
* Example 1) Getting a publicly-accessible raw file URL:
|
|
1684
|
+
*
|
|
1685
|
+
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg" })
|
|
1686
|
+
*
|
|
1687
|
+
* Example 2) Getting a publicly-accessible image URL, resized to 500x500:
|
|
1688
|
+
*
|
|
1689
|
+
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } } } })
|
|
1690
|
+
*
|
|
1691
|
+
* Example 3) Getting a privately-accessible image URL, resized to 500x500 (requires 'AuthManager.beginAuthSession' to be called before accessing the URL):
|
|
1692
|
+
*
|
|
1693
|
+
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } }, auth: true } })
|
|
1694
|
+
*
|
|
1695
|
+
* Example 4) Getting a publicly-accessible image URL, resized using a transformation preset called "thumbnail" that was created manually in the Bytescale Dashboard:
|
|
1696
|
+
*
|
|
1697
|
+
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "preset", preset: "thumbnail" } } })
|
|
1698
|
+
*/
|
|
1699
|
+
function url(params) {
|
|
1701
1700
|
var _a;
|
|
1702
1701
|
return ((_a = params.options) === null || _a === void 0 ? void 0 : _a.transformation) === undefined ? this.raw(params) : this.transformation(params, params.options);
|
|
1703
1702
|
}
|
|
@@ -1723,7 +1722,8 @@ var UrlBuilder = /*#__PURE__*/function () {
|
|
|
1723
1722
|
}, {
|
|
1724
1723
|
key: "getBaseUrl",
|
|
1725
1724
|
value: function getBaseUrl(params, prefix) {
|
|
1726
|
-
|
|
1725
|
+
var cdnUrl = BytescaleApiClientConfigUtils.defaultCdnUrl;
|
|
1726
|
+
return "".concat(cdnUrl, "/").concat(params.accountId, "/").concat(prefix).concat(params.filePath);
|
|
1727
1727
|
}
|
|
1728
1728
|
}, {
|
|
1729
1729
|
key: "getCommonTransformationQueryParams",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bytescale/sdk",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.17",
|
|
4
4
|
"description": "Bytescale JavaScript SDK",
|
|
5
5
|
"author": "Bytescale <hello@bytescale.com> (https://www.bytescale.com)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -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",
|
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
|
});
|