@ckeditor/ckeditor5-cloud-services 31.1.0 → 32.0.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/LICENSE.md CHANGED
@@ -2,7 +2,7 @@ Software License Agreement
2
2
  ==========================
3
3
 
4
4
  **CKEditor 5 Cloud Services integration** – https://github.com/ckeditor/ckeditor5-cloud-services <br>
5
- Copyright (c) 2003-2021, [CKSource](http://cksource.com) Frederico Knabben. All rights reserved.
5
+ Copyright (c) 2003-2022, [CKSource](http://cksource.com) Holding sp. z o.o. All rights reserved.
6
6
 
7
7
  Licensed under the terms of [GNU General Public License Version 2 or later](http://www.gnu.org/licenses/gpl.html).
8
8
 
@@ -14,4 +14,4 @@ Where not otherwise indicated, all CKEditor content is authored by CKSource engi
14
14
  Trademarks
15
15
  ----------
16
16
 
17
- **CKEditor** is a trademark of [CKSource](http://cksource.com) Frederico Knabben. All other brand and product names are trademarks, registered trademarks or service marks of their respective holders.
17
+ **CKEditor** is a trademark of [CKSource](http://cksource.com) Holding sp. z o.o. All other brand and product names are trademarks, registered trademarks or service marks of their respective holders.
@@ -1,5 +1,4 @@
1
1
  /*!
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource - Frederico Knabben. All rights reserved.
3
3
  * For licensing, see LICENSE.md.
4
- */
5
- window.CKEditor5=window.CKEditor5||{},window.CKEditor5.cloudServices=function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=3)}([function(e,t,r){e.exports=r(2)("./src/utils.js")},function(e,t,r){e.exports=r(2)("./src/core.js")},function(e,t){e.exports=CKEditor5.dll},function(e,t,r){"use strict";r.r(t),r.d(t,"CloudServices",(function(){return c})),r.d(t,"CloudServicesCore",(function(){return h}));var n=r(1),o=r(0);const s={autoRefresh:!0};class i{constructor(e,t=s){if(!e)throw new o.CKEditorError("token-missing-token-url",this);t.initValue&&this._validateTokenValue(t.initValue),this.set("value",t.initValue),this._refresh="function"==typeof e?e:()=>{return t=e,new Promise((e,r)=>{const n=new XMLHttpRequest;n.open("GET",t),n.addEventListener("load",()=>{const t=n.status,s=n.response;return t<200||t>299?r(new o.CKEditorError("token-cannot-download-new-token",null)):e(s)}),n.addEventListener("error",()=>r(new Error("Network Error"))),n.addEventListener("abort",()=>r(new Error("Abort"))),n.send()});var t},this._options=Object.assign({},s,t)}init(){return new Promise((e,t)=>{this.value?(this._options.autoRefresh&&this._registerRefreshTokenTimeout(),e(this)):this.refreshToken().then(e).catch(t)})}refreshToken(){return this._refresh().then(e=>{this._validateTokenValue(e),this.set("value",e),this._options.autoRefresh&&this._registerRefreshTokenTimeout()}).then(()=>this)}destroy(){clearTimeout(this._tokenRefreshTimeout)}_validateTokenValue(e){const t="string"==typeof e,r=!/^".*"$/.test(e),n=t&&3===e.split(".").length;if(!r||!n)throw new o.CKEditorError("token-not-in-jwt-format",this)}_registerRefreshTokenTimeout(){const e=this._getTokenRefreshTimeoutTime();clearTimeout(this._tokenRefreshTimeout),this._tokenRefreshTimeout=setTimeout(()=>{this.refreshToken()},e)}_getTokenRefreshTimeoutTime(){try{const[,e]=this.value.split("."),{exp:t}=JSON.parse(atob(e));if(!t)return 36e5;return Math.floor((1e3*t-Date.now())/2)}catch(e){return 36e5}}static create(e,t=s){return new i(e,t).init()}}Object(o.mix)(i,o.ObservableMixin);var a=i;const u=/^data:(\S*?);base64,/;class l{constructor(e,t,r){if(!e)throw new o.CKEditorError("fileuploader-missing-file",null);if(!t)throw new o.CKEditorError("fileuploader-missing-token",null);if(!r)throw new o.CKEditorError("fileuploader-missing-api-address",null);this.file=function(e){if("string"!=typeof e)return!1;const t=e.match(u);return!(!t||!t.length)}(e)?function(e,t=512){try{const r=e.match(u)[1],n=atob(e.replace(u,"")),o=[];for(let e=0;e<n.length;e+=t){const r=n.slice(e,e+t),s=new Array(r.length);for(let e=0;e<r.length;e++)s[e]=r.charCodeAt(e);o.push(new Uint8Array(s))}return new Blob(o,{type:r})}catch(e){throw new o.CKEditorError("fileuploader-decoding-image-data-error",null)}}(e):e,this._token=t,this._apiAddress=r}onProgress(e){return this.on("progress",(t,r)=>e(r)),this}onError(e){return this.once("error",(t,r)=>e(r)),this}abort(){this.xhr.abort()}send(){return this._prepareRequest(),this._attachXHRListeners(),this._sendRequest()}_prepareRequest(){const e=new XMLHttpRequest;e.open("POST",this._apiAddress),e.setRequestHeader("Authorization",this._token.value),e.responseType="json",this.xhr=e}_attachXHRListeners(){const e=this,t=this.xhr;function r(t){return()=>e.fire("error",t)}t.addEventListener("error",r("Network Error")),t.addEventListener("abort",r("Abort")),t.upload&&t.upload.addEventListener("progress",e=>{e.lengthComputable&&this.fire("progress",{total:e.total,uploaded:e.loaded})}),t.addEventListener("load",()=>{const e=t.status,r=t.response;if(e<200||e>299)return this.fire("error",r.message||r.error)})}_sendRequest(){const e=new FormData,t=this.xhr;return e.append("file",this.file),new Promise((r,n)=>{t.addEventListener("load",()=>{const e=t.status,s=t.response;return e<200||e>299?s.message?n(new o.CKEditorError("fileuploader-uploading-data-failed",this,{message:s.message})):n(s.error):r(s)}),t.addEventListener("error",()=>n(new Error("Network Error"))),t.addEventListener("abort",()=>n(new Error("Abort"))),t.send(e)})}}Object(o.mix)(l,o.EmitterMixin);class d{constructor(e,t){if(!e)throw new o.CKEditorError("uploadgateway-missing-token",null);if(!t)throw new o.CKEditorError("uploadgateway-missing-api-address",null);this._token=e,this._apiAddress=t}upload(e){return new l(e,this._token,this._apiAddress)}}class h extends n.ContextPlugin{static get pluginName(){return"CloudServicesCore"}createToken(e,t){return new a(e,t)}createUploadGateway(e,t){return new d(e,t)}}class c extends n.ContextPlugin{static get pluginName(){return"CloudServices"}static get requires(){return[h]}init(){const e=this.context.config.get("cloudServices")||{};for(const t in e)this[t]=e[t];if(this._tokens=new Map,this.tokenUrl)return this.token=this.context.plugins.get("CloudServicesCore").createToken(this.tokenUrl),this._tokens.set(this.tokenUrl,this.token),this.token.init();this.token=null}registerTokenUrl(e){if(this._tokens.has(e))return Promise.resolve(this.getTokenFor(e));const t=this.context.plugins.get("CloudServicesCore").createToken(e);return this._tokens.set(e,t),t.init()}getTokenFor(e){const t=this._tokens.get(e);if(!t)throw new o.CKEditorError("cloudservices-token-not-registered",this);return t}destroy(){super.destroy();for(const e of this._tokens.values())e.destroy()}}}]);
4
+ */(()=>{var e={704:(e,t,r)=>{e.exports=r(79)("./src/core.js")},209:(e,t,r)=>{e.exports=r(79)("./src/utils.js")},79:e=>{"use strict";e.exports=CKEditor5.dll}},t={};function r(s){var o=t[s];if(void 0!==o)return o.exports;var n=t[s]={exports:{}};return e[s](n,n.exports,r),n.exports}r.d=(e,t)=>{for(var s in t)r.o(t,s)&&!r.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:t[s]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var s={};(()=>{"use strict";r.r(s),r.d(s,{CloudServices:()=>c,CloudServicesCore:()=>d});var e=r(704),t=r(209);const o={autoRefresh:!0},n=36e5;class i{constructor(e,r=o){if(!e)throw new t.CKEditorError("token-missing-token-url",this);r.initValue&&this._validateTokenValue(r.initValue),this.set("value",r.initValue),this._refresh="function"==typeof e?e:()=>{return r=e,new Promise(((e,s)=>{const o=new XMLHttpRequest;o.open("GET",r),o.addEventListener("load",(()=>{const r=o.status,n=o.response;return r<200||r>299?s(new t.CKEditorError("token-cannot-download-new-token",null)):e(n)})),o.addEventListener("error",(()=>s(new Error("Network Error")))),o.addEventListener("abort",(()=>s(new Error("Abort")))),o.send()}));var r},this._options=Object.assign({},o,r)}init(){return new Promise(((e,t)=>{this.value?(this._options.autoRefresh&&this._registerRefreshTokenTimeout(),e(this)):this.refreshToken().then(e).catch(t)}))}refreshToken(){return this._refresh().then((e=>{this._validateTokenValue(e),this.set("value",e),this._options.autoRefresh&&this._registerRefreshTokenTimeout()})).then((()=>this))}destroy(){clearTimeout(this._tokenRefreshTimeout)}_validateTokenValue(e){const r="string"==typeof e,s=!/^".*"$/.test(e),o=r&&3===e.split(".").length;if(!s||!o)throw new t.CKEditorError("token-not-in-jwt-format",this)}_registerRefreshTokenTimeout(){const e=this._getTokenRefreshTimeoutTime();clearTimeout(this._tokenRefreshTimeout),this._tokenRefreshTimeout=setTimeout((()=>{this.refreshToken()}),e)}_getTokenRefreshTimeoutTime(){try{const[,e]=this.value.split("."),{exp:t}=JSON.parse(atob(e));if(!t)return n;return Math.floor((1e3*t-Date.now())/2)}catch(e){return n}}static create(e,t=o){return new i(e,t).init()}}(0,t.mix)(i,t.ObservableMixin);const a=i,u=/^data:(\S*?);base64,/;class h{constructor(e,r,s){if(!e)throw new t.CKEditorError("fileuploader-missing-file",null);if(!r)throw new t.CKEditorError("fileuploader-missing-token",null);if(!s)throw new t.CKEditorError("fileuploader-missing-api-address",null);this.file=function(e){if("string"!=typeof e)return!1;const t=e.match(u);return!(!t||!t.length)}(e)?function(e,r=512){try{const t=e.match(u)[1],s=atob(e.replace(u,"")),o=[];for(let e=0;e<s.length;e+=r){const t=s.slice(e,e+r),n=new Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);o.push(new Uint8Array(n))}return new Blob(o,{type:t})}catch(e){throw new t.CKEditorError("fileuploader-decoding-image-data-error",null)}}(e):e,this._token=r,this._apiAddress=s}onProgress(e){return this.on("progress",((t,r)=>e(r))),this}onError(e){return this.once("error",((t,r)=>e(r))),this}abort(){this.xhr.abort()}send(){return this._prepareRequest(),this._attachXHRListeners(),this._sendRequest()}_prepareRequest(){const e=new XMLHttpRequest;e.open("POST",this._apiAddress),e.setRequestHeader("Authorization",this._token.value),e.responseType="json",this.xhr=e}_attachXHRListeners(){const e=this,t=this.xhr;function r(t){return()=>e.fire("error",t)}t.addEventListener("error",r("Network Error")),t.addEventListener("abort",r("Abort")),t.upload&&t.upload.addEventListener("progress",(e=>{e.lengthComputable&&this.fire("progress",{total:e.total,uploaded:e.loaded})})),t.addEventListener("load",(()=>{const e=t.status,r=t.response;if(e<200||e>299)return this.fire("error",r.message||r.error)}))}_sendRequest(){const e=new FormData,r=this.xhr;return e.append("file",this.file),new Promise(((s,o)=>{r.addEventListener("load",(()=>{const e=r.status,n=r.response;return e<200||e>299?n.message?o(new t.CKEditorError("fileuploader-uploading-data-failed",this,{message:n.message})):o(n.error):s(n)})),r.addEventListener("error",(()=>o(new Error("Network Error")))),r.addEventListener("abort",(()=>o(new Error("Abort")))),r.send(e)}))}}(0,t.mix)(h,t.EmitterMixin);class l{constructor(e,r){if(!e)throw new t.CKEditorError("uploadgateway-missing-token",null);if(!r)throw new t.CKEditorError("uploadgateway-missing-api-address",null);this._token=e,this._apiAddress=r}upload(e){return new h(e,this._token,this._apiAddress)}}class d extends e.ContextPlugin{static get pluginName(){return"CloudServicesCore"}createToken(e,t){return new a(e,t)}createUploadGateway(e,t){return new l(e,t)}}class c extends e.ContextPlugin{static get pluginName(){return"CloudServices"}static get requires(){return[d]}init(){const e=this.context.config.get("cloudServices")||{};for(const t in e)this[t]=e[t];if(this._tokens=new Map,this.tokenUrl)return this.token=this.context.plugins.get("CloudServicesCore").createToken(this.tokenUrl),this._tokens.set(this.tokenUrl,this.token),this.token.init();this.token=null}registerTokenUrl(e){if(this._tokens.has(e))return Promise.resolve(this.getTokenFor(e));const t=this.context.plugins.get("CloudServicesCore").createToken(e);return this._tokens.set(e,t),t.init()}getTokenFor(e){const r=this._tokens.get(e);if(!r)throw new t.CKEditorError("cloudservices-token-not-registered",this);return r}destroy(){super.destroy();for(const e of this._tokens.values())e.destroy()}}})(),(window.CKEditor5=window.CKEditor5||{}).cloudServices=s})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-cloud-services",
3
- "version": "31.1.0",
3
+ "version": "32.0.0",
4
4
  "description": "CKEditor 5's Cloud Services integration layer.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -11,19 +11,19 @@
11
11
  ],
12
12
  "main": "src/index.js",
13
13
  "dependencies": {
14
- "ckeditor5": "^31.1.0"
14
+ "ckeditor5": "^32.0.0"
15
15
  },
16
16
  "devDependencies": {
17
- "@ckeditor/ckeditor5-core": "^31.1.0",
18
- "@ckeditor/ckeditor5-dev-utils": "^26.0.0",
19
- "@ckeditor/ckeditor5-editor-classic": "^31.1.0",
20
- "@ckeditor/ckeditor5-theme-lark": "^31.1.0",
21
- "@ckeditor/ckeditor5-utils": "^31.1.0",
22
- "webpack": "^4.43.0",
23
- "webpack-cli": "^3.3.11"
17
+ "@ckeditor/ckeditor5-core": "^32.0.0",
18
+ "@ckeditor/ckeditor5-dev-utils": "^27.1.0",
19
+ "@ckeditor/ckeditor5-editor-classic": "^32.0.0",
20
+ "@ckeditor/ckeditor5-theme-lark": "^32.0.0",
21
+ "@ckeditor/ckeditor5-utils": "^32.0.0",
22
+ "webpack": "^5.58.1",
23
+ "webpack-cli": "^4.9.0"
24
24
  },
25
25
  "engines": {
26
- "node": ">=12.0.0",
26
+ "node": ">=14.0.0",
27
27
  "npm": ">=5.7.1"
28
28
  },
29
29
  "author": "CKSource (http://cksource.com/)",
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
package/src/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5