Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.1.9 #24

Merged
merged 5 commits into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions .ember-cli
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
{
/**
Ember CLI sends analytics information by default. The data is completely
anonymous, but there are times when you might want to disable this behavior.

Setting `disableAnalytics` to true will prevent any data from being sent.
*/
"disableAnalytics": false,

/**
Setting `isTypeScriptProject` to true will force the blueprint generators to generate TypeScript
rather than JavaScript by default, when a TypeScript version of a given blueprint is available.
Setting `isTypeScriptProject` to true will force the blueprint generators to generate TypeScript
rather than JavaScript by default, when a TypeScript version of a given blueprint is available.
*/
"isTypeScriptProject": false
}
12 changes: 0 additions & 12 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
# unconventional js
/blueprints/*/files/
/vendor/

# compiled output
/dist/
/tmp/

# dependencies
/bower_components/
/node_modules/

# misc
/coverage/
!.*
.*/
.eslintcache

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/npm-shrinkwrap.json.ember-try
/package.json.ember-try
/package-lock.json.ember-try
/yarn.lock.ember-try
20 changes: 8 additions & 12 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

module.exports = {
root: true,
parser: 'babel-eslint',
parser: '@babel/eslint-parser',
parserOptions: {
ecmaVersion: 2018,
ecmaVersion: 'latest',
sourceType: 'module',
ecmaFeatures: {
legacyDecorators: true,
requireConfigFile: false,
babelOptions: {
plugins: [['@babel/plugin-proposal-decorators', { decoratorsBeforeExport: true }]],
},
},
plugins: ['ember'],
Expand All @@ -33,7 +34,7 @@ module.exports = {
'ember/no-incorrect-calls-with-inline-anonymous-functions': 'off',
'ember/no-private-routing-service': 'off',
'no-useless-escape': 'off',
'node/no-unpublished-require': [
'n/no-unpublished-require': [
'error',
{
allowModules: ['resolve', 'broccoli-funnel', 'broccoli-merge-trees'],
Expand All @@ -46,6 +47,7 @@ module.exports = {
files: [
'./.eslintrc.js',
'./.prettierrc.js',
'./.stylelintrc.js',
'./.template-lintrc.js',
'./ember-cli-build.js',
'./index.js',
Expand All @@ -61,13 +63,7 @@ module.exports = {
browser: false,
node: true,
},
plugins: ['node'],
extends: ['plugin:node/recommended'],
},
{
// test files
files: ['tests/**/*-test.{js,ts}'],
extends: ['plugin:qunit/recommended'],
extends: ['plugin:n/recommended'],
},
],
};
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

strategy:
matrix:
node-version: [16.x] # Build on Node.js 16
node-version: [18.x] # Build on Node.js 18

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -45,10 +45,10 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Setup Node.js 16.x
- name: Setup Node.js 18.x
uses: actions/setup-node@v2
with:
node-version: 16.x
node-version: 18.x

- name: Setup pnpm
uses: pnpm/[email protected]
Expand All @@ -74,10 +74,10 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Setup Node.js 16.x
- name: Setup Node.js 18.x
uses: actions/setup-node@v2
with:
node-version: 16.x
node-version: 18.x

- name: Setup pnpm
uses: pnpm/[email protected]
Expand Down
9 changes: 1 addition & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/dist/
/tmp/
/declarations/

# dependencies
/bower_components/
/node_modules/

# misc
/.env*
/.pnp*
/.sass-cache
/.eslintcache
/connect.lock
/coverage/
/libpeerconnection.log
/npm-debug.log*
/testem.log
/yarn-error.log

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/npm-shrinkwrap.json.ember-try
/package.json.ember-try
/package-lock.json.ember-try
Expand Down
9 changes: 2 additions & 7 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
/dist/
/tmp/

# dependencies
/bower_components/

# misc
/.bowerrc
/.editorconfig
/.ember-cli
/.env*
Expand All @@ -18,11 +14,11 @@
/.gitignore
/.prettierignore
/.prettierrc.js
/.stylelintignore
/.stylelintrc.js
/.template-lintrc.js
/.travis.yml
/.watchmanconfig
/bower.json
/config/ember-try.js
/CONTRIBUTING.md
/ember-cli-build.js
/testem.js
Expand All @@ -33,7 +29,6 @@

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/npm-shrinkwrap.json.ember-try
/package.json.ember-try
/package-lock.json.ember-try
Expand Down
14 changes: 1 addition & 13 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
# unconventional js
/blueprints/*/files/
/vendor/

# compiled output
/dist/
/tmp/

# dependencies
/bower_components/
/node_modules/

# misc
/coverage/
!.*
.eslintcache
.lint-todo/
.*/

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/npm-shrinkwrap.json.ember-try
/package.json.ember-try
/package-lock.json.ember-try
/yarn.lock.ember-try
2 changes: 1 addition & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
printWidth: 190,
overrides: [
{
files: '*.hbs',
files: '*.{hbs,js,ts}',
options: {
singleQuote: false,
},
Expand Down
8 changes: 8 additions & 0 deletions .stylelintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# unconventional files
/blueprints/*/files/

# compiled output
/dist/

# addons
/.node_modules.ember-try/
5 changes: 5 additions & 0 deletions .stylelintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = {
extends: ['stylelint-config-standard', 'stylelint-prettier/recommended'],
};
2 changes: 1 addition & 1 deletion .watchmanconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"ignore_dirs": ["tmp", "dist"]
"ignore_dirs": ["dist"]
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Ember Core Services, Utilities and Framework for building Fleetbase Extensions i

## Compatibility

* Ember.js v3.24 or above
* Ember CLI v3.24 or above
* Node.js v14 or above
* Ember.js v4.8 or above
* Ember CLI v4.8 or above
* Node.js v18 or above

## Installation

Expand Down
24 changes: 24 additions & 0 deletions addon/adapters/application.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import RESTAdapter from '@ember-data/adapter/rest';
import AdapterError from '@ember-data/adapter/error';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import { storageFor } from 'ember-local-storage';
Expand Down Expand Up @@ -145,4 +146,27 @@ export default class ApplicationAdapter extends RESTAdapter {
pathForType(type) {
return dasherize(pluralize(type));
}

/**
* Handles the response from an AJAX request in an Ember application.
*
* @param {number} status - The HTTP status code of the response.
* @param {object} headers - The headers of the response.
* @param {object} payload - The payload of the response.
* @return {Object | AdapterError} response - Returns a new `AdapterError` instance with detailed error information if the response is invalid; otherwise, it returns the result of the superclass's `handleResponse` method.
*
* This method first normalizes the error response and generates a detailed message.
* It then checks if the response is invalid based on the status code. If invalid, it constructs an `AdapterError` with the normalized errors and detailed message.
* For valid responses, it delegates the handling to the superclass's `handleResponse` method.
*/
handleResponse(status, headers, payload) {
let errors = this.normalizeErrorResponse(status, headers, payload);
let detailedMessage = this.generatedDetailedMessage(...arguments);

if (this.isInvalid(status, headers, payload)) {
return new AdapterError(errors, detailedMessage);
}

return super.handleResponse(...arguments);
}
}
15 changes: 10 additions & 5 deletions addon/services/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { get, set } from '@ember/object';
import { isBlank } from '@ember/utils';
import { dasherize } from '@ember/string';
import { isArray } from '@ember/array';
import { assign } from '@ember/polyfills';
import { singularize, pluralize } from 'ember-inflector';
import { task } from 'ember-concurrency';
import { storageFor } from 'ember-local-storage';
Expand Down Expand Up @@ -256,7 +255,7 @@ export default class FetchService extends Service {
* @return {Promise}
*/
request(path, method = 'GET', data = {}, options = {}) {
const headers = assign(this.getHeaders(), options.headers ?? {});
const headers = Object.assign(this.getHeaders(), options.headers ?? {});
const host = options.host ?? this.host;
const namespace = options.namespace ?? this.namespace;
const url = options.externalRequest === true ? path : [host, namespace, path].filter(Boolean).join('/');
Expand Down Expand Up @@ -525,6 +524,12 @@ export default class FetchService extends Service {
const { queue } = file;
const headers = this.getHeaders();

// make sure this task runs once for this file in correct state
// this can occur when the task is called twice when upload button exists inside upload dropzone
if (['queued', 'failed', 'timed_out', 'aborted'].indexOf(file.state) === -1) {
return;
}

// remove Content-Type header
delete headers['Content-Type'];

Expand All @@ -540,7 +545,7 @@ export default class FetchService extends Service {
})
.then((response) => response.json())
.catch((error) => {
this.notifications.serverError(error, `Upload failed.`);
this.notifications.serverError(error, 'File upload failed.');
});

const model = this.store.push(this.store.normalize('file', upload.file));
Expand All @@ -553,7 +558,7 @@ export default class FetchService extends Service {
return model;
} catch (error) {
queue.remove(file);
this.notifications.serverError(error, `Upload failed.`);
this.notifications.serverError(error, 'File upload failed.');

if (typeof errorCallback === 'function') {
errorCallback(error);
Expand All @@ -574,7 +579,7 @@ export default class FetchService extends Service {
* @return {Promise}
*/
download(path, query = {}, options = {}) {
const headers = assign(this.getHeaders(), options.headers ?? {});
const headers = Object.assign(this.getHeaders(), options.headers ?? {});

return new Promise((resolve, reject) => {
return fetch(`${options.host || this.host}/${options.namespace || this.namespace}/${path}?${!isBlank(query) ? new URLSearchParams(query).toString() : ''}`, {
Expand Down
Loading
Loading