@ghii/http-loader
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -11,17 +10,13 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const axios_1 = __importDefault(require("axios")); | ||
const http_loader_1 = __importDefault(require("../http-loader")); | ||
import axios from 'axios'; | ||
import httpLoader from '../http-loader'; | ||
jest.mock('axios'); | ||
const mockedAxios = axios_1.default; | ||
const mockedAxios = axios; | ||
describe('Ghii Http Loader', () => { | ||
it('export a function', () => { | ||
expect(typeof http_loader_1.default).toBe('function'); | ||
expect(typeof httpLoader).toBe('function'); | ||
}); | ||
describe('to create a loader', () => { | ||
it('create a file loader from yaml file', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const httpCallLoader = http_loader_1.default('http://localhost:3000/.wellknown'); | ||
const httpCallLoader = httpLoader('http://localhost:3000/.wellknown'); | ||
expect(typeof httpCallLoader).toBe('function'); | ||
@@ -31,3 +26,3 @@ })); | ||
mockedAxios.get.mockRejectedValue({ response: { status: 404 }, message: 'test' }); | ||
yield http_loader_1.default('http://localhost:3000/.wellknown')(); | ||
yield httpLoader('http://localhost:3000/.wellknown')(); | ||
})); | ||
@@ -37,3 +32,3 @@ it('attempt to make a call that fails', () => __awaiter(void 0, void 0, void 0, function* () { | ||
try { | ||
yield http_loader_1.default('http://localhost:3000/.wellknown', { throwOnError: true })(); | ||
yield httpLoader('http://localhost:3000/.wellknown', { throwOnError: true })(); | ||
} | ||
@@ -45,5 +40,25 @@ catch (err) { | ||
})); | ||
it('attempt to make a call that fails 2', () => __awaiter(void 0, void 0, void 0, function* () { | ||
mockedAxios.get.mockRejectedValue(undefined); | ||
try { | ||
yield httpLoader('http://localhost:3000/.wellknown', { throwOnError: true })(); | ||
} | ||
catch (err) { | ||
expect(err).toBeDefined(); | ||
expect(err.message).toContain('GET'); | ||
} | ||
})); | ||
it('attempt to make a call that fails 3', () => __awaiter(void 0, void 0, void 0, function* () { | ||
mockedAxios.get.mockRejectedValue({ message: 'test' }); | ||
try { | ||
yield httpLoader('http://localhost:3000/.wellknown', { throwOnError: true })(); | ||
} | ||
catch (err) { | ||
expect(err).toBeDefined(); | ||
expect(err.message).toContain('test'); | ||
} | ||
})); | ||
it('attempt to call api resolved', () => __awaiter(void 0, void 0, void 0, function* () { | ||
mockedAxios.get.mockResolvedValue({ data: { test: 'value' } }); | ||
const test = yield http_loader_1.default('http://localhost:3000/.wellknown')(); | ||
const test = yield httpLoader('http://localhost:3000/.wellknown')(); | ||
expect(test).toStrictEqual({ test: 'value' }); | ||
@@ -50,0 +65,0 @@ })); |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -11,8 +10,4 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const axios_1 = __importDefault(require("axios")); | ||
function httpLoader(urlEndpoint, { headers, throwOnError = false, logger = (err, message) => console.log(message, err), } = {}) { | ||
import axios from 'axios'; | ||
export default function httpLoader(urlEndpoint, { headers, throwOnError = false, logger = (err, message) => console.log(message, err), } = {}) { | ||
return function () { | ||
@@ -22,7 +17,8 @@ var _a; | ||
try { | ||
const { data } = yield axios_1.default.get(urlEndpoint, { headers }); | ||
const { data } = yield axios.get(urlEndpoint, { headers }); | ||
return data; | ||
} | ||
catch (err) { | ||
const msg = `${(_a = err === null || err === void 0 ? void 0 : err.response) === null || _a === void 0 ? void 0 : _a.status} GET ${urlEndpoint} : ${err.message}`; | ||
const axiosErr = err; | ||
const msg = `${((_a = axiosErr === null || axiosErr === void 0 ? void 0 : axiosErr.response) === null || _a === void 0 ? void 0 : _a.status) || ''} GET ${urlEndpoint} : ${axiosErr === null || axiosErr === void 0 ? void 0 : axiosErr.message}`; | ||
logger(err, msg); | ||
@@ -36,3 +32,3 @@ if (throwOnError) | ||
} | ||
exports.default = httpLoader; | ||
export { httpLoader }; | ||
//# sourceMappingURL=http-loader.js.map |
@@ -7,2 +7,3 @@ import { Loader } from '@ghii/ghii'; | ||
}): Loader; | ||
export { httpLoader }; | ||
//# sourceMappingURL=http-loader.d.ts.map |
{ | ||
"name": "@ghii/http-loader", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "A Funny http loader for ghii configuration manager ", | ||
@@ -38,5 +38,5 @@ "maintainers": [ | ||
"scripts": { | ||
"lint": "tslint --project tsconfig.json -t codeFrame 'src/**/*.ts' 'test/**/*.ts'", | ||
"lint": "eslint . --ext .ts,.tsx", | ||
"prebuild": "rimraf dist", | ||
"build": "tsc --module commonjs && typedoc --out docs --target es6 --theme minimal --mode file src", | ||
"build": "tsc", | ||
"start": "rollup -c rollup.config.ts -w", | ||
@@ -75,24 +75,24 @@ "test": "jest --coverage", | ||
"devDependencies": { | ||
"@ghii/ghii": "0.0.1", | ||
"@types/jest": "^26.0.15", | ||
"@types/node": "^14.14.6", | ||
"@typescript-eslint/eslint-plugin": "^4.6.1", | ||
"@typescript-eslint/parser": "^4.6.1", | ||
"coveralls": "^3.1.0", | ||
"cross-env": "^7.0.2", | ||
"eslint": "^7.13.0", | ||
"eslint-config-prettier": "^6.15.0", | ||
"eslint-plugin-prettier": "^3.1.4", | ||
"jest": "^26.6.3", | ||
"jest-config": "^26.6.3", | ||
"prettier": "^2.1.2", | ||
"@ghii/ghii": "1.0.0", | ||
"@types/jest": "^29.2.3", | ||
"@types/node": "^18.11.9", | ||
"@typescript-eslint/eslint-plugin": "^5.45.0", | ||
"@typescript-eslint/parser": "^5.45.0", | ||
"coveralls": "^3.1.1", | ||
"cross-env": "^7.0.3", | ||
"eslint": "^8.28.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"jest": "^29.3.1", | ||
"jest-config": "^29.3.1", | ||
"prettier": "^2.8.0", | ||
"rimraf": "^3.0.2", | ||
"ts-jest": "^26.4.3", | ||
"ts-node": "^9.0.0", | ||
"typedoc": "^0.19.2", | ||
"typescript": "^4.0.5" | ||
"ts-jest": "^29.0.3", | ||
"ts-node": "^10.9.1", | ||
"typedoc": "^0.23.21", | ||
"typescript": "^4.9.3" | ||
}, | ||
"dependencies": { | ||
"axios": "^0.21.0" | ||
"axios": "^1.2.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
12419
101
1
+ Addedasynckit@0.4.0(transitive)
+ Addedaxios@1.7.2(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedform-data@4.0.0(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedproxy-from-env@1.1.0(transitive)
- Removedaxios@0.21.4(transitive)
Updatedaxios@^1.2.0