@bytescale/sdk 3.21.0 → 3.21.1
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 +8 -10
- package/dist/browser/cjs/main.js +1 -1
- package/dist/browser/esm/main.mjs +1 -1
- package/dist/node/cjs/main.js +1 -1
- package/dist/node/esm/main.mjs +1 -1
- package/dist/types/private/model/AuthManagerInterface.d.ts +4 -6
- package/dist/types/public/shared/UrlBuilderTypes.d.ts +1 -5
- package/dist/worker/cjs/main.js +1 -1
- package/dist/worker/esm/main.mjs +1 -1
- package/package.json +1 -1
- package/tests/UrlBuilder.test.ts +5 -6
package/README.md
CHANGED
|
@@ -406,13 +406,13 @@ https://upcdn.io/W142hJk/image/example/city-landscape.jpg
|
|
|
406
406
|
&color=ffe400
|
|
407
407
|
```
|
|
408
408
|
|
|
409
|
-
##
|
|
409
|
+
## Authentication
|
|
410
410
|
|
|
411
|
-
The Bytescale JavaScript SDK supports two types of
|
|
411
|
+
The Bytescale JavaScript SDK supports two types of authentication:
|
|
412
412
|
|
|
413
413
|
### API Keys
|
|
414
414
|
|
|
415
|
-
The Bytescale JavaScript SDK automatically adds the `apiKey` from the constructor to the `
|
|
415
|
+
The Bytescale JavaScript SDK automatically adds the `apiKey` from the constructor to the `authorization` header for all requests made via the SDK.
|
|
416
416
|
|
|
417
417
|
With API key auth, the requester has access to the resources available to the API key:
|
|
418
418
|
|
|
@@ -422,17 +422,15 @@ With API key auth, the requester has access to the resources available to the AP
|
|
|
422
422
|
|
|
423
423
|
Each Public API Key and Secret API Key can have its read/write access limited to a subset of files/folders.
|
|
424
424
|
|
|
425
|
-
###
|
|
425
|
+
### JWTs
|
|
426
426
|
|
|
427
|
-
|
|
427
|
+
JWTs are optional.
|
|
428
428
|
|
|
429
|
-
With
|
|
429
|
+
With JWTs, the user can download private files directly via the URL, as authentication is performed implicitly via a session cookie _or_ via an `authorization` header if service workers are used (see the `serviceWorkerScript` param on the `AuthManager.beginAuthSession` method). This allows the browser to display private files in `<img>` and `<video>` elements.
|
|
430
430
|
|
|
431
|
-
With
|
|
431
|
+
With JWTs, the user can also perform API requests, such as file uploads, as these can be granted by the [JWT's payload](https://www.bytescale.com/docs/types/BytescaleJwt). The Bytescale JavaScript SDK will automatically inject the user's JWT into the `authorization-token` request header for all API requests, assuming the `AuthManager.beginAuthSession` method has been called.
|
|
432
432
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
[Learn more about the `AuthManager` and JWT cookies »](https://www.bytescale.com/docs/authorization#jwt-cookie)
|
|
433
|
+
[Learn more about the `AuthManager` and JWTs »](https://www.bytescale.com/docs/auth)
|
|
436
434
|
|
|
437
435
|
## UrlBuilder
|
|
438
436
|
|
package/dist/browser/cjs/main.js
CHANGED
|
@@ -1617,7 +1617,7 @@ var UrlBuilder = /*#__PURE__*/function () {
|
|
|
1617
1617
|
}, {
|
|
1618
1618
|
key: "getCommonQueryParams",
|
|
1619
1619
|
value: function getCommonQueryParams(params) {
|
|
1620
|
-
return this.makeQueryParams(["
|
|
1620
|
+
return this.makeQueryParams(["cache", "cacheTtl", "version", "forceDownloadPrompt"], {
|
|
1621
1621
|
cacheTtl: "cache_ttl",
|
|
1622
1622
|
forceDownloadPrompt: "download"
|
|
1623
1623
|
})(params);
|
|
@@ -1602,7 +1602,7 @@ var UrlBuilder = /*#__PURE__*/function () {
|
|
|
1602
1602
|
}, {
|
|
1603
1603
|
key: "getCommonQueryParams",
|
|
1604
1604
|
value: function getCommonQueryParams(params) {
|
|
1605
|
-
return this.makeQueryParams(["
|
|
1605
|
+
return this.makeQueryParams(["cache", "cacheTtl", "version", "forceDownloadPrompt"], {
|
|
1606
1606
|
cacheTtl: "cache_ttl",
|
|
1607
1607
|
forceDownloadPrompt: "download"
|
|
1608
1608
|
})(params);
|
package/dist/node/cjs/main.js
CHANGED
|
@@ -1617,7 +1617,7 @@ var UrlBuilder = /*#__PURE__*/function () {
|
|
|
1617
1617
|
}, {
|
|
1618
1618
|
key: "getCommonQueryParams",
|
|
1619
1619
|
value: function getCommonQueryParams(params) {
|
|
1620
|
-
return this.makeQueryParams(["
|
|
1620
|
+
return this.makeQueryParams(["cache", "cacheTtl", "version", "forceDownloadPrompt"], {
|
|
1621
1621
|
cacheTtl: "cache_ttl",
|
|
1622
1622
|
forceDownloadPrompt: "download"
|
|
1623
1623
|
})(params);
|
package/dist/node/esm/main.mjs
CHANGED
|
@@ -1604,7 +1604,7 @@ var UrlBuilder = /*#__PURE__*/function () {
|
|
|
1604
1604
|
}, {
|
|
1605
1605
|
key: "getCommonQueryParams",
|
|
1606
1606
|
value: function getCommonQueryParams(params) {
|
|
1607
|
-
return this.makeQueryParams(["
|
|
1607
|
+
return this.makeQueryParams(["cache", "cacheTtl", "version", "forceDownloadPrompt"], {
|
|
1608
1608
|
cacheTtl: "cache_ttl",
|
|
1609
1609
|
forceDownloadPrompt: "download"
|
|
1610
1610
|
})(params);
|
|
@@ -69,7 +69,7 @@ export interface AuthManagerInterface {
|
|
|
69
69
|
/**
|
|
70
70
|
* Begins a JWT auth session with the Bytescale API and Bytescale CDN.
|
|
71
71
|
*
|
|
72
|
-
* Specifically, calling this method will cause the SDK to periodically acquire a JWT from your JWT endpoint. The SDK will then automatically include this JWT in all subsequent Bytescale API requests (via the 'authorization-token' request header) and also in all Bytescale CDN download requests (via a session cookie).
|
|
72
|
+
* Specifically, calling this method will cause the SDK to periodically acquire a JWT from your JWT endpoint. The SDK will then automatically include this JWT in all subsequent Bytescale API requests (via the 'authorization-token' request header) and also in all Bytescale CDN download requests (via a session cookie, or an 'authorization' header if service workers are being used).
|
|
73
73
|
*
|
|
74
74
|
* You can only call this method if 'isAuthSessionActive() === false', else an error will be returned.
|
|
75
75
|
*
|
|
@@ -79,17 +79,15 @@ export interface AuthManagerInterface {
|
|
|
79
79
|
*
|
|
80
80
|
* After calling this method:
|
|
81
81
|
*
|
|
82
|
-
* 1) You must
|
|
83
|
-
*
|
|
84
|
-
* 2) You must await the returned promise before attempting to perform any downloads or API operations that require authentication.
|
|
82
|
+
* 1) You must await the returned promise before attempting to perform any downloads or API operations that require authentication.
|
|
85
83
|
*
|
|
86
84
|
* The auth process works as follows:
|
|
87
85
|
*
|
|
88
86
|
* 1) After you call this method, the AuthManager will periodically fetch a JWT in plain text from the given 'authUrl'.
|
|
89
87
|
*
|
|
90
|
-
* 2) The JWT will be
|
|
88
|
+
* 2) The JWT will be added as a request header via 'authorization-token' to all Bytescale API requests made via this SDK. This allows the user to upload private files and perform administrative operations permitted by the JWT, such as deleting files, etc.
|
|
91
89
|
*
|
|
92
|
-
* 3) The JWT will also
|
|
90
|
+
* 3) The JWT will be also saved to a cookie scoped to the Bytescale CDN if service workers are not being used (see the 'serviceWorkerScript' field). This allows the user to view private files via the URL in the browser, including <img> elements on the page that reference private images, etc. If service workers are being used, then the JWT will be submitted to the Bytescale CDN via the 'authorization' header instead.
|
|
93
91
|
*/
|
|
94
92
|
beginAuthSession: (params: BeginAuthSessionParams) => Promise<void>;
|
|
95
93
|
/**
|
|
@@ -25,11 +25,7 @@ export declare type UrlBuilderTransformationOptions = UrlBuilderTransformationAp
|
|
|
25
25
|
export declare type UrlBuilderTransformationApiOptions = UrlBuilderOptionsImage | UrlBuilderOptionsVideo | UrlBuilderOptionsAudio | UrlBuilderOptionsArchive;
|
|
26
26
|
export interface UrlBuilderOptionsBase {
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* Set to 'false' or omit when downloading publicly-accessible files.
|
|
31
|
-
*
|
|
32
|
-
* Default: false
|
|
28
|
+
* @deprecated This field has no effect: the 'auth' querystring parameter is no-longer required by the Bytescale CDN. You may remove this field from your code.
|
|
33
29
|
*/
|
|
34
30
|
auth?: boolean;
|
|
35
31
|
/**
|
package/dist/worker/cjs/main.js
CHANGED
|
@@ -1617,7 +1617,7 @@ var UrlBuilder = /*#__PURE__*/function () {
|
|
|
1617
1617
|
}, {
|
|
1618
1618
|
key: "getCommonQueryParams",
|
|
1619
1619
|
value: function getCommonQueryParams(params) {
|
|
1620
|
-
return this.makeQueryParams(["
|
|
1620
|
+
return this.makeQueryParams(["cache", "cacheTtl", "version", "forceDownloadPrompt"], {
|
|
1621
1621
|
cacheTtl: "cache_ttl",
|
|
1622
1622
|
forceDownloadPrompt: "download"
|
|
1623
1623
|
})(params);
|
package/dist/worker/esm/main.mjs
CHANGED
|
@@ -1602,7 +1602,7 @@ var UrlBuilder = /*#__PURE__*/function () {
|
|
|
1602
1602
|
}, {
|
|
1603
1603
|
key: "getCommonQueryParams",
|
|
1604
1604
|
value: function getCommonQueryParams(params) {
|
|
1605
|
-
return this.makeQueryParams(["
|
|
1605
|
+
return this.makeQueryParams(["cache", "cacheTtl", "version", "forceDownloadPrompt"], {
|
|
1606
1606
|
cacheTtl: "cache_ttl",
|
|
1607
1607
|
forceDownloadPrompt: "download"
|
|
1608
1608
|
})(params);
|
package/package.json
CHANGED
package/tests/UrlBuilder.test.ts
CHANGED
|
@@ -9,7 +9,7 @@ describe("UrlBuilder", () => {
|
|
|
9
9
|
|
|
10
10
|
test("raw file with one param", () => {
|
|
11
11
|
const actual = UrlBuilder.url({ accountId: "1234abc", filePath: "/example.jpg", options: { auth: true } });
|
|
12
|
-
const expected = "https://upcdn.io/1234abc/raw/example.jpg
|
|
12
|
+
const expected = "https://upcdn.io/1234abc/raw/example.jpg";
|
|
13
13
|
expect(actual).toEqual(expected);
|
|
14
14
|
});
|
|
15
15
|
|
|
@@ -19,7 +19,7 @@ describe("UrlBuilder", () => {
|
|
|
19
19
|
filePath: "/example.jpg",
|
|
20
20
|
options: { auth: true, cache: true, version: "42" }
|
|
21
21
|
});
|
|
22
|
-
const expected = "https://upcdn.io/1234abc/raw/example.jpg?
|
|
22
|
+
const expected = "https://upcdn.io/1234abc/raw/example.jpg?cache=true&version=42";
|
|
23
23
|
expect(actual).toEqual(expected);
|
|
24
24
|
});
|
|
25
25
|
|
|
@@ -29,7 +29,7 @@ describe("UrlBuilder", () => {
|
|
|
29
29
|
filePath: "/example.jpg",
|
|
30
30
|
options: { auth: true, cache: true, cacheTtl: 100 } // cacheTtl is rewritten to cache_ttl
|
|
31
31
|
});
|
|
32
|
-
const expected = "https://upcdn.io/1234abc/raw/example.jpg?
|
|
32
|
+
const expected = "https://upcdn.io/1234abc/raw/example.jpg?cache=true&cache_ttl=100";
|
|
33
33
|
expect(actual).toEqual(expected);
|
|
34
34
|
});
|
|
35
35
|
|
|
@@ -121,8 +121,7 @@ describe("UrlBuilder", () => {
|
|
|
121
121
|
auth: true
|
|
122
122
|
}
|
|
123
123
|
});
|
|
124
|
-
const expected =
|
|
125
|
-
"https://upcdn.io/1234abc/image/example.jpg?w=42&h=50&auth=true&version=50&cache_perm=auto&artifact=%2Ffoo";
|
|
124
|
+
const expected = "https://upcdn.io/1234abc/image/example.jpg?w=42&h=50&version=50&cache_perm=auto&artifact=%2Ffoo";
|
|
126
125
|
expect(actual).toEqual(expected);
|
|
127
126
|
});
|
|
128
127
|
|
|
@@ -140,7 +139,7 @@ describe("UrlBuilder", () => {
|
|
|
140
139
|
auth: true
|
|
141
140
|
}
|
|
142
141
|
});
|
|
143
|
-
const expected = "https://upcdn.io/1234abc/image/example.jpg?r=52
|
|
142
|
+
const expected = "https://upcdn.io/1234abc/image/example.jpg?r=52";
|
|
144
143
|
expect(actual).toEqual(expected);
|
|
145
144
|
});
|
|
146
145
|
|