@bytescale/sdk 3.20.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 CHANGED
@@ -406,13 +406,13 @@ https://upcdn.io/W142hJk/image/example/city-landscape.jpg
406
406
  &color=ffe400
407
407
  ```
408
408
 
409
- ## Authorization
409
+ ## Authentication
410
410
 
411
- The Bytescale JavaScript SDK supports two types of authorization:
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 `Authorization` header for all requests made via the SDK.
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
- ### JWT Cookies
425
+ ### JWTs
426
426
 
427
- JWT cookies are optional.
427
+ JWTs are optional.
428
428
 
429
- With JWT cookies, the user can download private files directly via the URL, as authorization is performed implicitly via a session cookie. This allows the browser to display private files in `<img>` and `<video>` elements.
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 JWT cookies, the user can also perform API requests (e.g. file uploads) granted by the [JWT's payload](https://www.bytescale.com/docs/types/BytescaleJwt). This is because the Bytescale JavaScript SDK automatically injects the user's JWT into the `authorization-token` request header for all API requests, assuming the `AuthManager.beginAuthSession` method has been called.
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
- _Note: when using JWT cookies to download files, the `?auth=true` query parameter must be added to the URL._
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
 
@@ -1617,7 +1617,7 @@ var UrlBuilder = /*#__PURE__*/function () {
1617
1617
  }, {
1618
1618
  key: "getCommonQueryParams",
1619
1619
  value: function getCommonQueryParams(params) {
1620
- return this.makeQueryParams(["auth", "cache", "cacheTtl", "version", "forceDownloadPrompt"], {
1620
+ return this.makeQueryParams(["cache", "cacheTtl", "version", "forceDownloadPrompt"], {
1621
1621
  cacheTtl: "cache_ttl",
1622
1622
  forceDownloadPrompt: "download"
1623
1623
  })(params);
@@ -2534,9 +2534,7 @@ var ServiceWorkerUtils = /*#__PURE__*/function () {
2534
2534
  var installing = registration.installing;
2535
2535
  return ServiceWorkerUtils_invoke(function () {
2536
2536
  if (installing !== null) {
2537
- installing.postMessage(init);
2538
- _exit2 = true;
2539
- return ServiceWorkerUtils_await(new Promise(function (resolve) {
2537
+ var waitForActive = new Promise(function (resolve) {
2540
2538
  var stateChangeHandler = function stateChangeHandler(e) {
2541
2539
  var sw = e.target;
2542
2540
  if (sw.state === "activated") {
@@ -2548,7 +2546,10 @@ var ServiceWorkerUtils = /*#__PURE__*/function () {
2548
2546
  }
2549
2547
  };
2550
2548
  installing.addEventListener("statechange", stateChangeHandler);
2551
- }));
2549
+ });
2550
+ installing.postMessage(init);
2551
+ _exit2 = true;
2552
+ return ServiceWorkerUtils_await(waitForActive);
2552
2553
  }
2553
2554
  }, function (_result) {
2554
2555
  if (_exit2) return _result;
@@ -1602,7 +1602,7 @@ var UrlBuilder = /*#__PURE__*/function () {
1602
1602
  }, {
1603
1603
  key: "getCommonQueryParams",
1604
1604
  value: function getCommonQueryParams(params) {
1605
- return this.makeQueryParams(["auth", "cache", "cacheTtl", "version", "forceDownloadPrompt"], {
1605
+ return this.makeQueryParams(["cache", "cacheTtl", "version", "forceDownloadPrompt"], {
1606
1606
  cacheTtl: "cache_ttl",
1607
1607
  forceDownloadPrompt: "download"
1608
1608
  })(params);
@@ -2519,9 +2519,7 @@ var ServiceWorkerUtils = /*#__PURE__*/function () {
2519
2519
  var installing = registration.installing;
2520
2520
  return ServiceWorkerUtils_invoke(function () {
2521
2521
  if (installing !== null) {
2522
- installing.postMessage(init);
2523
- _exit2 = true;
2524
- return ServiceWorkerUtils_await(new Promise(function (resolve) {
2522
+ var waitForActive = new Promise(function (resolve) {
2525
2523
  var stateChangeHandler = function stateChangeHandler(e) {
2526
2524
  var sw = e.target;
2527
2525
  if (sw.state === "activated") {
@@ -2533,7 +2531,10 @@ var ServiceWorkerUtils = /*#__PURE__*/function () {
2533
2531
  }
2534
2532
  };
2535
2533
  installing.addEventListener("statechange", stateChangeHandler);
2536
- }));
2534
+ });
2535
+ installing.postMessage(init);
2536
+ _exit2 = true;
2537
+ return ServiceWorkerUtils_await(waitForActive);
2537
2538
  }
2538
2539
  }, function (_result) {
2539
2540
  if (_exit2) return _result;
@@ -1617,7 +1617,7 @@ var UrlBuilder = /*#__PURE__*/function () {
1617
1617
  }, {
1618
1618
  key: "getCommonQueryParams",
1619
1619
  value: function getCommonQueryParams(params) {
1620
- return this.makeQueryParams(["auth", "cache", "cacheTtl", "version", "forceDownloadPrompt"], {
1620
+ return this.makeQueryParams(["cache", "cacheTtl", "version", "forceDownloadPrompt"], {
1621
1621
  cacheTtl: "cache_ttl",
1622
1622
  forceDownloadPrompt: "download"
1623
1623
  })(params);
@@ -1604,7 +1604,7 @@ var UrlBuilder = /*#__PURE__*/function () {
1604
1604
  }, {
1605
1605
  key: "getCommonQueryParams",
1606
1606
  value: function getCommonQueryParams(params) {
1607
- return this.makeQueryParams(["auth", "cache", "cacheTtl", "version", "forceDownloadPrompt"], {
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 add '?auth=true' to the URL of any private file you're trying to access. This includes the URLs you use in 'src' elements in img/video elements, etc.
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 saved to a cookie scoped to the Bytescale CDN. 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.
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 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.
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
- * Set to 'true' to download a private file. Requires an active auth session. See AuthManager.beginAuthSession.
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
  /**
@@ -1617,7 +1617,7 @@ var UrlBuilder = /*#__PURE__*/function () {
1617
1617
  }, {
1618
1618
  key: "getCommonQueryParams",
1619
1619
  value: function getCommonQueryParams(params) {
1620
- return this.makeQueryParams(["auth", "cache", "cacheTtl", "version", "forceDownloadPrompt"], {
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(["auth", "cache", "cacheTtl", "version", "forceDownloadPrompt"], {
1605
+ return this.makeQueryParams(["cache", "cacheTtl", "version", "forceDownloadPrompt"], {
1606
1606
  cacheTtl: "cache_ttl",
1607
1607
  forceDownloadPrompt: "download"
1608
1608
  })(params);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytescale/sdk",
3
- "version": "3.20.0",
3
+ "version": "3.21.1",
4
4
  "description": "Bytescale JavaScript SDK",
5
5
  "author": "Bytescale <hello@bytescale.com> (https://www.bytescale.com)",
6
6
  "license": "MIT",
@@ -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?auth=true";
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?auth=true&cache=true&version=42";
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?auth=true&cache=true&cache_ttl=100";
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&auth=true";
142
+ const expected = "https://upcdn.io/1234abc/image/example.jpg?r=52";
144
143
  expect(actual).toEqual(expected);
145
144
  });
146
145