@fleetbase/ember-core 0.1.9 → 0.2.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.
@@ -95,7 +95,9 @@ export default class ApplicationAdapter extends RESTAdapter {
95
95
  const localStorageSession = JSON.parse(window.localStorage.getItem('ember_simple_auth-session'));
96
96
  if (localStorageSession) {
97
97
  const { authenticated } = localStorageSession;
98
- token = authenticated.token;
98
+ if (authenticated) {
99
+ token = authenticated.token;
100
+ }
99
101
 
100
102
  // Check isAuthenticated again
101
103
  isAuthenticated = !!token;
@@ -1,5 +1,17 @@
1
1
  import Base from 'ember-simple-auth/authenticators/base';
2
2
  import { inject as service } from '@ember/service';
3
+ import getWithDefault from '../utils/get-with-default';
4
+
5
+ export class AuthenticationError extends Error {
6
+ constructor(message, code) {
7
+ super(message);
8
+ this.code = code;
9
+ }
10
+
11
+ getCode() {
12
+ return this.code;
13
+ }
14
+ }
3
15
 
4
16
  export default class FleetbaseAuthenticator extends Base {
5
17
  /**
@@ -35,7 +47,7 @@ export default class FleetbaseAuthenticator extends Base {
35
47
  )
36
48
  .then((response) => {
37
49
  if (response.restore === false) {
38
- return Promise.reject(new Error(response.error));
50
+ return Promise.reject(new AuthenticationError(response.error));
39
51
  }
40
52
 
41
53
  return response;
@@ -52,7 +64,10 @@ export default class FleetbaseAuthenticator extends Base {
52
64
  authenticate(credentials = {}, remember = false, path = 'auth/login') {
53
65
  return this.fetch.post(path, { ...credentials, remember }).then((response) => {
54
66
  if (response.errors) {
55
- return Promise.reject(new Error(response.errors.firstObject ?? 'Authentication failed!'));
67
+ const errorMessage = getWithDefault(response.errors, '0', 'Authentication failed!');
68
+ const errorCode = getWithDefault(response, 'code');
69
+
70
+ return Promise.reject(new AuthenticationError(errorMessage, errorCode));
56
71
  }
57
72
 
58
73
  return response;
@@ -546,16 +546,24 @@ export default class FetchService extends Service {
546
546
  .then((response) => response.json())
547
547
  .catch((error) => {
548
548
  this.notifications.serverError(error, 'File upload failed.');
549
+
550
+ if (typeof errorCallback === 'function') {
551
+ errorCallback(error);
552
+ }
549
553
  });
550
554
 
551
- const model = this.store.push(this.store.normalize('file', upload.file));
552
- set(file, 'model', model);
555
+ if (upload) {
556
+ const model = this.store.push(this.store.normalize('file', upload.file));
557
+ set(file, 'model', model);
558
+
559
+ if (typeof callback === 'function') {
560
+ callback(model);
561
+ }
553
562
 
554
- if (typeof callback === 'function') {
555
- callback(model);
563
+ return model;
556
564
  }
557
565
 
558
- return model;
566
+ return null;
559
567
  } catch (error) {
560
568
  queue.remove(file);
561
569
  this.notifications.serverError(error, 'File upload failed.');
@@ -16,7 +16,11 @@ export default class NotificationsService extends EmberNotificationsService {
16
16
  return this.error(errorMessage, options);
17
17
  }
18
18
 
19
- return this.error(error ?? fallbackMessage, options);
19
+ if (typeof error === 'string') {
20
+ return this.error(error, options);
21
+ }
22
+
23
+ return this.error(fallbackMessage, options);
20
24
  }
21
25
 
22
26
  invoke(type, message, ...params) {
@@ -2,6 +2,7 @@ import SimpleAuthSessionService from 'ember-simple-auth/services/session';
2
2
  import { tracked } from '@glimmer/tracking';
3
3
  import { inject as service } from '@ember/service';
4
4
  import { later } from '@ember/runloop';
5
+ import getWithDefault from '../utils/get-with-default';
5
6
 
6
7
  export default class SessionService extends SimpleAuthSessionService {
7
8
  /**
@@ -97,12 +98,12 @@ export default class SessionService extends SimpleAuthSessionService {
97
98
  const user = await this.currentUser.load();
98
99
 
99
100
  if (!user) {
100
- return this.invalidateWithLoader(`Session authentication failed...`);
101
+ return this.invalidateWithLoader('Session authentication failed...');
101
102
  }
102
103
 
103
104
  return user;
104
105
  } catch (error) {
105
- await this.invalidateWithLoader(error.message ?? `Session authentication failed...`);
106
+ await this.invalidateWithLoader(getWithDefault(error, 'message', 'Session authentication failed...'));
106
107
  }
107
108
  }
108
109
 
@@ -124,7 +125,7 @@ export default class SessionService extends SimpleAuthSessionService {
124
125
  transition.abort();
125
126
  }
126
127
 
127
- reject(invalidateWithLoader(`Session authentication failed...`));
128
+ reject(invalidateWithLoader('Session authentication failed...'));
128
129
  }
129
130
 
130
131
  resolve(user);
@@ -218,4 +219,17 @@ export default class SessionService extends SimpleAuthSessionService {
218
219
 
219
220
  return Math.round((now - date) / 1000);
220
221
  }
222
+
223
+ /**
224
+ * Checks for the presence of two-factor authentication for a given user identity.
225
+ *
226
+ * @param {String} identity
227
+ * @return {Promise}
228
+ * @throws {Error}
229
+ */
230
+ checkForTwoFactor(identity) {
231
+ return this.fetch.get('two-fa/check', { identity }).catch((error) => {
232
+ throw new Error(error.message);
233
+ });
234
+ }
221
235
  }
@@ -759,6 +759,12 @@ export default class UniverseService extends Service.extend(Evented) {
759
759
  const index = this._getOption(options, 'index', 0);
760
760
  const onClick = this._getOption(options, 'onClick', null);
761
761
  const section = this._getOption(options, 'section', null);
762
+ const iconSize = this._getOption(options, 'iconSize', null);
763
+ const iconClass = this._getOption(options, 'iconClass', null);
764
+ const itemClass = this._getOption(options, 'class', null);
765
+ const inlineClass = this._getOption(options, 'inlineClass', null);
766
+ const wrapperClass = this._getOption(options, 'wrapperClass', null);
767
+ const overwriteWrapperClass = this._getOption(options, 'overwriteWrapperClass', false);
762
768
 
763
769
  // dasherize route segments
764
770
  if (typeof route === 'string') {
@@ -784,6 +790,12 @@ export default class UniverseService extends Service.extend(Evented) {
784
790
  index,
785
791
  section,
786
792
  onClick,
793
+ iconSize,
794
+ iconClass,
795
+ class: itemClass,
796
+ inlineClass,
797
+ wrapperClass,
798
+ overwriteWrapperClass,
787
799
  };
788
800
 
789
801
  return menuItem;
@@ -1,10 +1,16 @@
1
- export default function getResourceNameFromTransition(transition) {
1
+ import humanize from './humanize';
2
+
3
+ export default function getResourceNameFromTransition(transition, options = {}) {
2
4
  const { to } = transition;
3
5
 
4
6
  if (typeof to.name === 'string') {
5
7
  let routePathSegments = to.name.split('.');
6
8
  let resourceName = routePathSegments[3];
7
9
 
10
+ if (options.humanize === true) {
11
+ return humanize(resourceName);
12
+ }
13
+
8
14
  return resourceName;
9
15
  }
10
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fleetbase/ember-core",
3
- "version": "0.1.9",
3
+ "version": "0.2.1",
4
4
  "description": "Provides all the core services, decorators and utilities for building a Fleetbase extension for the Console.",
5
5
  "keywords": [
6
6
  "fleetbase-core",
@@ -1,28 +0,0 @@
1
- /* eslint-disable no-unused-vars */
2
- import extractCoordinates from './extract-coordinates';
3
- import Terraformer from 'terraformer';
4
- import { isArray } from '@ember/array';
5
-
6
- export default function extractLatitude(position) {
7
- let latitude, longitude;
8
-
9
- if (!position) {
10
- return 0;
11
- }
12
-
13
- if (position instanceof Terraformer.Point || isArray(position.coordinates)) {
14
- [latitude, longitude] = extractCoordinates(position.coordinates);
15
-
16
- return latitude;
17
- }
18
-
19
- if (typeof position === 'object') {
20
- let latitude = position['lat'] || position['latitude'] || position['x'];
21
-
22
- return latitude;
23
- }
24
-
25
- [latitude, longitude] = extractCoordinates(position);
26
-
27
- return latitude;
28
- }
@@ -1,28 +0,0 @@
1
- /* eslint-disable no-unused-vars */
2
- import extractCoordinates from './extract-coordinates';
3
- import Terraformer from 'terraformer';
4
- import { isArray } from '@ember/array';
5
-
6
- export default function extractLongitude(position) {
7
- let latitude, longitude;
8
-
9
- if (!position) {
10
- return 0;
11
- }
12
-
13
- if (position instanceof Terraformer.Point || isArray(position.coordinates)) {
14
- [latitude, longitude] = extractCoordinates(position.coordinates);
15
-
16
- return longitude;
17
- }
18
-
19
- if (typeof position === 'object') {
20
- let longitude = position['lng'] || position['longitude'] || position['lon'] || position['y'];
21
-
22
- return longitude;
23
- }
24
-
25
- [latitude, longitude] = extractCoordinates(position);
26
-
27
- return longitude;
28
- }
@@ -1 +0,0 @@
1
- export { default } from '@fleetbase/ember-core/utils/extract-latitude';
@@ -1 +0,0 @@
1
- export { default } from '@fleetbase/ember-core/utils/extract-longitude';