8
0
Quellcode durchsuchen

Merge pull request #2 from ckeditor/t/1

Feature: Initialise repository and CloudeServices plugin. Closes #1.
Piotr Jasiun vor 8 Jahren
Ursprung
Commit
226f7fb173

+ 12 - 0
packages/ckeditor5-cloud-services/.editorconfig

@@ -0,0 +1,12 @@
+# Configurations to normalize the IDE behavior.
+# http://editorconfig.org/
+
+root = true
+
+[*]
+indent_style = tab
+tab_width = 4
+charset = utf-8
+end_of_line = lf
+trim_trailing_whitespace = true
+insert_final_newline = true

+ 12 - 0
packages/ckeditor5-cloud-services/.eslintrc.js

@@ -0,0 +1,12 @@
+/**
+ * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* eslint-env node */
+
+'use strict';
+
+module.exports = {
+	extends: 'ckeditor5'
+};

+ 18 - 0
packages/ckeditor5-cloud-services/.gitattributes

@@ -0,0 +1,18 @@
+*			text=auto
+
+*.htaccess	eol=lf
+*.cgi		eol=lf
+*.sh		eol=lf
+
+*.css		text
+*.htm		text
+*.html		text
+*.js		text
+*.json		text
+*.php		text
+*.txt		text
+*.md		text
+
+*.png		-text
+*.gif		-text
+*.jpg		-text

+ 1 - 0
packages/ckeditor5-cloud-services/.gitignore

@@ -0,0 +1 @@
+node_modules/

+ 24 - 0
packages/ckeditor5-cloud-services/.travis.yml

@@ -0,0 +1,24 @@
+sudo: required
+dist: trusty
+addons:
+  apt:
+    sources:
+      - google-chrome
+    packages:
+      - google-chrome-stable
+language: node_js
+node_js:
+  - "6"
+cache:
+  - node_modules
+before_install:
+  - export DISPLAY=:99.0
+  - sh -e /etc/init.d/xvfb start
+install:
+  - npm install @ckeditor/ckeditor5-dev-tests
+  - ckeditor5-dev-tests-install-dependencies
+script:
+  - ckeditor5-dev-tests-travis
+after_success:
+  - codeclimate-test-reporter < coverage/lcov.info
+  - ckeditor5-dev-tests-save-revision

+ 4 - 0
packages/ckeditor5-cloud-services/CONTRIBUTING.md

@@ -0,0 +1,4 @@
+Contributing
+========================================
+
+Information about contributing can be found at the following page: <https://github.com/ckeditor/ckeditor5/blob/master/CONTRIBUTING.md>.

+ 23 - 0
packages/ckeditor5-cloud-services/LICENSE.md

@@ -0,0 +1,23 @@
+Software License Agreement
+==========================
+
+**CKEditor 5 Cloud Services** – https://github.com/ckeditor/ckeditor5-cloudservices <br>
+Copyright (c) 2003-2017, [CKSource](http://cksource.com) Frederico Knabben. All rights reserved.
+
+Licensed under the terms of any of the following licenses at your choice:
+
+* [GNU General Public License Version 2 or later (the "GPL")](http://www.gnu.org/licenses/gpl.html)
+* [GNU Lesser General Public License Version 2.1 or later (the "LGPL")](http://www.gnu.org/licenses/lgpl.html)
+* [Mozilla Public License Version 1.1 or later (the "MPL")](http://www.mozilla.org/MPL/MPL-1.1.html)
+
+You are not required to, but if you want to explicitly declare the license you have chosen to be bound to when using, reproducing, modifying and distributing this software, just include a text file titled "legal.txt" in your version of this software, indicating your license choice. In any case, your choice will not restrict any recipient of your version of this software to use, reproduce, modify and distribute this software under any of the above licenses.
+
+Sources of Intellectual Property Included in CKEditor
+-----------------------------------------------------
+
+Where not otherwise indicated, all CKEditor content is authored by CKSource engineers and consists of CKSource-owned intellectual property. In some specific instances, CKEditor will incorporate work done by developers outside of CKSource with their express permission.
+
+Trademarks
+----------
+
+**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 - 0
packages/ckeditor5-cloud-services/README.md

@@ -1,2 +1,19 @@
 CKEditor 5 Cloud Services base package
 ======================================
+
+[![Join the chat at https://gitter.im/ckeditor/ckeditor5](https://badges.gitter.im/ckeditor/ckeditor5.svg)](https://gitter.im/ckeditor/ckeditor5?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
+[![npm version](https://badge.fury.io/js/%40ckeditor%2Fckeditor5-cloudservices.svg)](https://www.npmjs.com/package/@ckeditor/ckeditor5-cloudservices)
+[![Build Status](https://travis-ci.org/ckeditor/ckeditor5-cloudservices.svg?branch=master)](https://travis-ci.org/ckeditor/ckeditor5-cloudservices)
+[![Test Coverage](https://codeclimate.com/github/ckeditor/ckeditor5-cloudservices/badges/coverage.svg)](https://codeclimate.com/github/ckeditor/ckeditor5-cloudservices/coverage)
+[![Dependency Status](https://david-dm.org/ckeditor/ckeditor5-cloudservices/status.svg)](https://david-dm.org/ckeditor/ckeditor5-cloudservices)
+[![devDependency Status](https://david-dm.org/ckeditor/ckeditor5-cloudservices/dev-status.svg)](https://david-dm.org/ckeditor/ckeditor5-cloudservices?type=dev)
+
+Base package for Cloud Services' integration, which handles CKEditor's `cloudservices` configuration and tokens.
+
+## Documentation
+
+See the [`@ckeditor/ckeditor5-cloudservices` package](https://ckeditor5.github.io/docs/nightly/ckeditor5/latest/api/cloudservices.html) page in [CKEditor 5 documentation](https://ckeditor5.github.io/docs/nightly/ckeditor5/latest/).
+
+## License
+
+Licensed under the GPL, LGPL and MPL licenses, at your choice. For full details about the license, please check the `LICENSE.md` file.

+ 47 - 0
packages/ckeditor5-cloud-services/package.json

@@ -0,0 +1,47 @@
+{
+  "name": "@ckeditor/ckeditor5-cloudservices",
+  "version": "1.0.0-alpha.1",
+  "description": "Base package for CKEditor 5' Cloud Services.",
+  "keywords": [
+    "ckeditor5"
+  ],
+  "dependencies": {
+	"@ckeditor/ckeditor-cloudservices-core": "^0.2.0",
+	"@ckeditor/ckeditor5-core": "^1.0.0-alpha.1",
+	"@ckeditor/ckeditor5-utils": "^1.0.0-alpha.1"
+  },
+  "devDependencies": {
+	"eslint": "^4.8.0",
+    "eslint-config-ckeditor5": "^1.0.6",
+    "husky": "^0.14.3",
+    "lint-staged": "^4.2.3"
+  },
+  "engines": {
+    "node": ">=6.0.0",
+    "npm": ">=3.0.0"
+  },
+  "author": "CKSource (http://cksource.com/)",
+  "license": "(GPL-2.0 OR LGPL-2.1 OR MPL-1.1)",
+  "homepage": "https://ckeditor5.github.io",
+  "bugs": "https://github.com/ckeditor/ckeditor5-cloudservices/issues",
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/ckeditor/ckeditor5-cloudservices.git"
+  },
+  "files": [
+    "src"
+  ],
+  "scripts": {
+    "lint": "eslint --quiet '**/*.js'",
+    "precommit": "lint-staged"
+  },
+  "lint-staged": {
+    "**/*.js": [
+      "eslint --quiet"
+    ]
+  },
+  "eslintIgnore": [
+    "src/lib/**",
+    "packages/**"
+  ]
+}

+ 100 - 0
packages/ckeditor5-cloud-services/src/cloudservices.js

@@ -0,0 +1,100 @@
+/**
+ * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/**
+ * @module cloudservices/cloudservices
+ */
+
+import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
+import Token from '@ckeditor/ckeditor-cloudservices-core/src/token/token';
+import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
+
+/**
+ * Base plugin for Cloud Services. It takes care about the `cloudServices` config options and initializes token provider.
+ */
+export default class CloudServices extends Plugin {
+	/**
+	 * @inheritDoc
+	 */
+	init() {
+		const editor = this.editor;
+		const config = editor.config;
+
+		const options = config.get( 'cloudServices' );
+
+		for ( const optionName in options ) {
+			this[ optionName ] = options[ optionName ];
+		}
+
+		/**
+		 * The authentication token URL for CloudServices.
+		 *
+		 * @readonly
+		 * @member {String} #tokenUrl
+		 */
+
+		if ( !this.tokenUrl ) {
+			/**
+			 * The authentication `cloudServices.token` config is not provided.
+			 *
+			 * @error cloudservices-token-endpoint-not-provided
+			 */
+			throw new CKEditorError(
+				'cloudservices-token-endpoint-not-provided: The authentication `cloudServices.token` config is not provided.'
+			);
+		}
+
+		/**
+		 * Other plugins use this token for authorization process. It handles token requesting and refreshing.
+		 *
+		 * @readonly
+		 */
+		this.token = new CloudServices.Token( this.tokenUrl );
+
+		return this.token.init();
+	}
+}
+
+CloudServices.Token = Token;
+
+/**
+ * The configuration of the Cloud Services. Introduced by the {@link module:cloudservices/cloudservices~CloudServices} plugin.
+ *
+ * Read more in {@link module:cloudservices/cloudservices~CloudServices}.
+ *
+ * @member {module:cloudservices/cloudservices~CloudServicesConfig} module:core/editor/editorconfig~EditorConfig#cloudServices
+ */
+
+/**
+ * The configuration for all plugins using Cloud Services.
+ *
+ *		ClassicEditor
+ *			.create( {
+ * 				cloudServices: ... // CloudServices config.
+ *			} )
+ *			.then( ... )
+ *			.catch( ... );
+ *
+ * @interface CloudServicesConfig
+ */
+
+/**
+ * The authentication token URL for CloudServices. Token us used to authenticate all plugins using CloudServices,
+ * for instance Easy Image. The token URL have to point to the service where the token is generated.
+ *
+ *		ClassicEditor
+ *			.create( document.querySelector( '#editor' ), {
+ *				cloudServices: {
+ *					tokenUrl: TOKEN_URL
+ *				},
+ * 				plugins: [ ArticlePluginSet, EasyImage ],
+ *				toolbar: [ 'headings', 'undo', 'redo', 'insertImage' ],
+ *				image: {
+ *					toolbar: [ 'imageStyleFull', 'imageStyleSide', '|', 'imageTextAlternative' ]
+ *				}
+ *			} );
+ *
+ * @member {String} module:cloudservices/cloudservices~CloudServicesConfig#tokenUrl
+ */

+ 12 - 0
packages/ckeditor5-cloud-services/tests/_utils/cloudservices-config.js

@@ -0,0 +1,12 @@
+/**
+ * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+// WARNING: The URLs below should not be used for any other purpose than Easy Image plugin development.
+// Images uploaded using the testing token service may be deleted automatically at any moment.
+// If you would like to try the Easy Image service, please wait until the official launch of Easy Image and sign up for a free trial.
+// Images uploaded during the free trial will not be deleted for the whole trial period and additionally the trial service can be converted
+// into a subscription at any moment, allowing you to preserve all uploaded images.
+
+export const TOKEN_URL = 'https://j2sns7jmy0.execute-api.eu-central-1.amazonaws.com/prod/token-new';

+ 27 - 0
packages/ckeditor5-cloud-services/tests/_utils/tokenmock.js

@@ -0,0 +1,27 @@
+/**
+ * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+import Token from '@ckeditor/ckeditor-cloudservices-core/src/token/token';
+
+export default class TokenMock extends Token {
+	/**
+	 * Overrides request and set the next token
+	 *
+	 * @protected
+	 * @returns {Promise.<Token>}
+	 */
+	_refreshToken() {
+		this.set( 'value', TokenMock.initialToken );
+
+		return Promise.resolve( this );
+	}
+
+	/**
+	 * Overrides interval
+	 *
+	 * @protected
+	 */
+	_startRefreshing() {}
+}

+ 83 - 0
packages/ckeditor5-cloud-services/tests/cloudservices.js

@@ -0,0 +1,83 @@
+/**
+ * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* global document */
+
+import CloudServices from '../src/cloudservices';
+import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
+import TokenMock from './_utils/tokenmock';
+
+const Token = CloudServices.Token;
+
+describe( 'CloudServices', () => {
+	let element;
+
+	beforeEach( () => {
+		CloudServices.Token = TokenMock;
+		element = document.createElement( 'div' );
+		document.body.appendChild( element );
+	} );
+
+	afterEach( () => {
+		CloudServices.Token = Token;
+		document.body.removeChild( element );
+	} );
+
+	describe( 'init()', () => {
+		it( 'should expose option property based on config', () => {
+			return ClassicTestEditor
+				.create( element, {
+					plugins: [ CloudServices ],
+					cloudServices: {
+						tokenUrl: 'http://token-endpoint',
+						additionalOption: 'some-value'
+					}
+				} )
+				.then( editor => {
+					const cloudServicesPlugin = editor.plugins.get( CloudServices );
+
+					expect( cloudServicesPlugin ).to.be.instanceOf( CloudServices );
+					expect( cloudServicesPlugin.tokenUrl ).to.equal( 'http://token-endpoint' );
+					expect( cloudServicesPlugin.additionalOption ).to.equal( 'some-value' );
+
+					return editor.destroy();
+				} );
+		} );
+
+		it( 'should provide token', () => {
+			CloudServices.Token.initialToken = 'initial-token';
+
+			return ClassicTestEditor
+				.create( element, {
+					plugins: [ CloudServices ],
+					cloudServices: {
+						tokenUrl: 'http://token-endpoint',
+					}
+				} )
+				.then( editor => {
+					const cloudServicesPlugin = editor.plugins.get( CloudServices );
+
+					expect( cloudServicesPlugin.token.value ).to.equal( 'initial-token' );
+
+					return editor.destroy();
+				} );
+		} );
+
+		it( 'should throw an error when token URL is not provided', done => {
+			CloudServices.Token.initialToken = 'initial-token';
+
+			ClassicTestEditor
+				.create( element, {
+					plugins: [ CloudServices ],
+					cloudServices: {}
+				} )
+				.catch( err => {
+					expect( err.name ).to.equal( 'CKEditorError' );
+					expect( err.message, '12' ).to.match( /cloudservices-token-endpoint-not-provided/ );
+					done();
+				} );
+		} );
+	} );
+} );