@sedoo/unidoo 0.1.9 → 0.1.11

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/index.js ADDED
@@ -0,0 +1,8 @@
1
+ // legacy support import Unidoo from "@sedoo/unidoo"
2
+ import plugin from "./src/plugin";
3
+ const Unidoo = plugin;
4
+ export default Unidoo;
5
+
6
+ // Enables "cherry pick" imports (e.g: import { Unidoo, UnidooKeycloak } from "@sedoo/unidoo")
7
+ export { default as Unidoo} from "./src/plugin";
8
+ export { default as UnidooKeycloak} from "./src/auth";
package/package.json CHANGED
@@ -1,87 +1,92 @@
1
1
  {
2
- "name": "@sedoo/unidoo",
3
- "version": "0.1.9",
4
- "private": false,
5
- "scripts": {
6
- "build": "vue-cli-service build --target lib --name unidoo src/plugin.js",
7
- "lint": "vue-cli-service lint --fix && vue-cli-service lint dev --fix",
8
- "docs:dev": "vuepress dev docs",
9
- "docs:build": "vuepress build docs"
2
+ "name": "@sedoo/unidoo",
3
+ "version": "0.1.11",
4
+ "private": false,
5
+ "scripts": {
6
+ "build": "npm run build:unidoo && npm run build:auth",
7
+ "build:unidoo": "vue-cli-service build --target lib --dest dist/unidoo --name unidoo src/plugin.js",
8
+ "build:auth": "vue-cli-service build --target lib --dest dist/auth --name auth src/auth.js",
9
+ "lint": "vue-cli-service lint --fix && vue-cli-service lint dev --fix",
10
+ "docs:dev": "vuepress dev docs",
11
+ "docs:build": "vuepress build docs"
12
+ },
13
+ "comments": {
14
+ "scripts": "The build and docs:build script are used in the continuous integration process. They musn't be removed."
15
+ },
16
+ "files": [
17
+ "index.js",
18
+ "dist",
19
+ "src/**/*"
20
+ ],
21
+ "dependencies": {
22
+ "date-fns": "^2.28.0",
23
+ "date-fns-tz": "^1.3.6",
24
+ "keycloak-js": "^8.0.2",
25
+ "ol": "^6.8.1",
26
+ "v-tooltip": "^2.1.3",
27
+ "vue-axios": "3.2.4"
28
+ },
29
+ "devDependencies": {
30
+ "@vue/cli-plugin-babel": "4.5.7",
31
+ "@vue/cli-plugin-eslint": "4.5.7",
32
+ "@vue/cli-service": "4.5.7",
33
+ "@vue/eslint-config-standard": "5.1.2",
34
+ "axios": "0.21.2",
35
+ "babel-eslint": "10.1.0",
36
+ "core-js": "3.6.5",
37
+ "eslint": "7.10.0",
38
+ "eslint-plugin-import": "2.22.1",
39
+ "eslint-plugin-node": "11.1.0",
40
+ "eslint-plugin-promise": "4.2.1",
41
+ "eslint-plugin-standard": "4.0.0",
42
+ "eslint-plugin-vue": "7.0.1",
43
+ "sass": "1.27.0",
44
+ "sass-loader": "10.0.2",
45
+ "vue": "2.6.14",
46
+ "vue-cli-plugin-vuetify": "2.0.7",
47
+ "vue-json-tree": "0.4.3",
48
+ "vue-json-tree-view": "2.1.6",
49
+ "vue-template-compiler": "2.6.14",
50
+ "vuepress": "1.8.2",
51
+ "vuetify": "2.3.13",
52
+ "vuetify-loader": "1.6.0",
53
+ "webpack-cdn-upload-plugin": "2.0.2"
54
+ },
55
+ "eslintConfig": {
56
+ "root": true,
57
+ "env": {
58
+ "node": true
10
59
  },
11
- "comments": {
12
- "scripts": "The build and docs:build script are used in the continuous integration process. They musn't be removed."
13
- },
14
- "files": [
15
- "dist",
16
- "src/**/*"
17
- ],
18
- "dependencies": {
19
- "date-fns": "^2.28.0",
20
- "date-fns-tz": "^1.3.6",
21
- "ol": "^6.8.1",
22
- "v-tooltip": "^2.1.3",
23
- "vue-axios": "3.2.4"
24
- },
25
- "devDependencies": {
26
- "@vue/cli-plugin-babel": "4.5.7",
27
- "@vue/cli-plugin-eslint": "4.5.7",
28
- "@vue/cli-service": "4.5.7",
29
- "@vue/eslint-config-standard": "5.1.2",
30
- "axios": "0.21.2",
31
- "babel-eslint": "10.1.0",
32
- "core-js": "3.6.5",
33
- "eslint": "7.10.0",
34
- "eslint-plugin-import": "2.22.1",
35
- "eslint-plugin-node": "11.1.0",
36
- "eslint-plugin-promise": "4.2.1",
37
- "eslint-plugin-standard": "4.0.0",
38
- "eslint-plugin-vue": "7.0.1",
39
- "sass": "1.27.0",
40
- "sass-loader": "10.0.2",
41
- "vue": "2.6.14",
42
- "vue-cli-plugin-vuetify": "2.0.7",
43
- "vue-json-tree": "0.4.3",
44
- "vue-json-tree-view": "2.1.6",
45
- "vue-template-compiler": "2.6.14",
46
- "vuepress": "1.8.2",
47
- "vuetify": "2.3.13",
48
- "vuetify-loader": "1.6.0",
49
- "webpack-cdn-upload-plugin": "2.0.2"
50
- },
51
- "eslintConfig": {
52
- "root": true,
53
- "env": {
54
- "node": true
55
- },
56
- "extends": [
57
- "plugin:vue/essential",
58
- "eslint:recommended"
59
- ],
60
- "rules": {
61
- "no-console": 0,
62
- "no-debugger": 0,
63
- "no-trailing-spaces": 0,
64
- "comma-dangle": 0,
65
- "indent": 0
66
- },
67
- "parserOptions": {
68
- "parser": "babel-eslint"
69
- }
70
- },
71
- "browserslist": [
72
- "> 1%",
73
- "last 2 versions"
60
+ "extends": [
61
+ "plugin:vue/essential",
62
+ "eslint:recommended"
74
63
  ],
75
- "description": "Commons components to simplify vuetify based application developement",
76
- "main": "./dist/unidoo.common.js",
77
- "module": "./dist/unidoo.umd.min.js",
78
- "repository": {
79
- "type": "git",
80
- "url": "git+https://gitlab.in2p3.fr/sedoo/unidoo.git"
81
- },
82
- "author": "SEDOO",
83
- "bugs": {
84
- "url": "https://gitlab.in2p3.fr/sedoo/unidoo/-/issues"
64
+ "rules": {
65
+ "no-console": 0,
66
+ "no-debugger": 0,
67
+ "no-trailing-spaces": 0,
68
+ "comma-dangle": 0,
69
+ "indent": 0
85
70
  },
86
- "homepage": "https://sedoo.pages.in2p3.fr/unidoo"
71
+ "parserOptions": {
72
+ "parser": "babel-eslint"
73
+ }
74
+ },
75
+ "browserslist": [
76
+ "> 1%",
77
+ "last 2 versions"
78
+ ],
79
+ "description": "Commons components to simplify vuetify based application developement",
80
+ "exports": {
81
+ ".": "./index.js"
82
+ },
83
+ "repository": {
84
+ "type": "git",
85
+ "url": "https://gitlab.in2p3.fr/sedoo/unidoo.git"
86
+ },
87
+ "author": "SEDOO",
88
+ "bugs": {
89
+ "url": "https://gitlab.in2p3.fr/sedoo/unidoo/-/issues"
90
+ },
91
+ "homepage": "https://sedoo.pages.in2p3.fr/unidoo"
87
92
  }
package/src/auth.js ADDED
@@ -0,0 +1,91 @@
1
+ import { isEmpty } from "lodash";
2
+ import Keycloak from "keycloak-js";
3
+
4
+ const UnidooKeycloak = {
5
+ install(Vue, { axios }) {
6
+ if (this.installed) return;
7
+ this.installed = true;
8
+
9
+ /**
10
+ * Init keycloak with SSO parameters
11
+ * @param {*} options SSO parameters
12
+ */
13
+ Vue.prototype.$unidooInitKeycloak = async (options) => {
14
+ handleErrors(options);
15
+
16
+ let defaultOptions = {
17
+ ssoParams: {}
18
+ };
19
+ defaultOptions = { ...options };
20
+
21
+ const keycloak = Keycloak(defaultOptions.ssoParams);
22
+ Vue.prototype.$keycloak = keycloak;
23
+
24
+ keycloak
25
+ .init({
26
+ onLoad: "check-sso",
27
+ promiseType: "native",
28
+ checkLoginIframe: false
29
+ })
30
+ .then(() => {
31
+ // Intercepteur qui ajoute le token aux requêtes
32
+ interceptRequests(
33
+ axios,
34
+ defaultOptions.ssoParams.authorizedDomains,
35
+ keycloak.token
36
+ );
37
+ updateSSoToken(keycloak);
38
+ });
39
+ };
40
+ }
41
+ };
42
+
43
+ export default UnidooKeycloak;
44
+
45
+ function handleErrors(options) {
46
+ if (!options.ssoParams || Object.keys(options.ssoParams).length === 0) {
47
+ throw new Error(
48
+ "You need to provide sso parameters for the plugin to work."
49
+ );
50
+ }
51
+
52
+ const someParametersAreNull = Object.values(
53
+ options.ssoParams
54
+ ).some((parameter) => isEmpty(parameter));
55
+
56
+ if (someParametersAreNull) {
57
+ const emptyProperties = [];
58
+ for (const property in options.ssoParams) {
59
+ if (isEmpty(options.ssoParams[property])) {
60
+ emptyProperties.push(property);
61
+ }
62
+ }
63
+
64
+ throw new Error(
65
+ `The following properties are required : ${emptyProperties.join(", ")}`
66
+ );
67
+ }
68
+ }
69
+
70
+ function updateSSoToken(keycloak) {
71
+ setTimeout(function() {
72
+ keycloak.updateToken(200000);
73
+ updateSSoToken(keycloak);
74
+ }, 200000);
75
+ }
76
+
77
+ function interceptRequests(axios, authorizedDomains, token) {
78
+ axios.interceptors.request.use(
79
+ (config) => {
80
+ if (
81
+ authorizedDomains.some((url) => config.url.startsWith(url)) &&
82
+ token
83
+ ) {
84
+ config.headers.Authorization = "Bearer " + token;
85
+ config.headers.Accept = "application/json, text/plain, */*";
86
+ }
87
+ return config;
88
+ },
89
+ (error) => Promise.reject(error)
90
+ );
91
+ }
File without changes
File without changes