diff --git a/CHANGELOG.md b/CHANGELOG.md index 865c17a..578643c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # react-wordpress-hooks Changelog -## 1.0.0 alpha 1 (Soon) +## 0.1.1 (2019-06-11) +#### Improvement +- improved response error output + +## 0.1.0 (2019-06-11) #### New Feature **context** - `WPContext` with url & auth values diff --git a/lib/react-wordpress-hooks.js b/lib/react-wordpress-hooks.js new file mode 100644 index 0000000..ef2ea03 --- /dev/null +++ b/lib/react-wordpress-hooks.js @@ -0,0 +1,758 @@ +module.exports = +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) { +/******/ return installedModules[moduleId].exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // define getter function for harmony exports +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!__webpack_require__.o(exports, name)) { +/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); +/******/ } +/******/ }; +/******/ +/******/ // define __esModule on exports +/******/ __webpack_require__.r = function(exports) { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ +/******/ // create a fake namespace object +/******/ // mode & 1: value is a module id, require it +/******/ // mode & 2: merge all properties of value into the ns +/******/ // mode & 4: return value when already ns object +/******/ // mode & 8|1: behave like require +/******/ __webpack_require__.t = function(value, mode) { +/******/ if(mode & 1) value = __webpack_require__(value); +/******/ if(mode & 8) return value; +/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; +/******/ var ns = Object.create(null); +/******/ __webpack_require__.r(ns); +/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); +/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); +/******/ return ns; +/******/ }; +/******/ +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(__webpack_require__.s = "./src/index.tsx"); +/******/ }) +/************************************************************************/ +/******/ ({ + +/***/ "./src/context.tsx": +/*!*************************!*\ + !*** ./src/context.tsx ***! + \*************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const react_1 = __importDefault(__webpack_require__(/*! react */ "react")); +exports.WPContext = react_1.default.createContext({ + url: '', + auth: { + email: '', + password: '' + } +}); + + +/***/ }), + +/***/ "./src/hooks/useApiRequest.tsx": +/*!*************************************!*\ + !*** ./src/hooks/useApiRequest.tsx ***! + \*************************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const react_1 = __webpack_require__(/*! react */ "react"); +const context_1 = __webpack_require__(/*! ../context */ "./src/context.tsx"); +const utils_1 = __webpack_require__(/*! ../utils */ "./src/utils/index.tsx"); +exports.useApiRequest = ({ options, requsetMethod = 'get', endpoint = '' }) => { + const { url, auth } = react_1.useContext(context_1.WPContext); + const [data, setData] = react_1.useState([]); + const [loading, setLoading] = react_1.useState(false); + const [error, setError] = react_1.useState(null); + react_1.useEffect(() => { + const loadData = () => __awaiter(this, void 0, void 0, function* () { + try { + setLoading(true); + const res = yield fetch(`${url}/wp-json/wp/v2${endpoint ? `/${endpoint}` : ''}${typeof options === 'number' && requsetMethod === 'get' + ? `/${options}` + : utils_1.serialize(options)}`, { + method: requsetMethod, + headers: { + Authorization: `Basic ${btoa(`${auth.email}:${auth.password}`)}` + } + }); + const response = yield res.json(); + setLoading(false); + if (response.code) { + setError(response); + } + else { + setData(response); + } + } + catch (err) { + setLoading(false); + setError(err); + } + }); + loadData(); + }, [auth.email, auth.password, endpoint, options, requsetMethod, url]); + return { data, loading, error }; +}; + + +/***/ }), + +/***/ "./src/hooks/useCategories.tsx": +/*!*************************************!*\ + !*** ./src/hooks/useCategories.tsx ***! + \*************************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", { value: true }); +const useApiRequest_1 = __webpack_require__(/*! ./useApiRequest */ "./src/hooks/useApiRequest.tsx"); +const endpoint = 'categories'; +exports.useCategories = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ + options, + endpoint + }); + return { data, loading, error }; +}; +exports.useCreateCategory = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ + options, + endpoint, + requsetMethod: 'post' + }); + return { data, loading, error }; +}; +exports.useRetriveCategory = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ + options, + endpoint + }); + return { data, loading, error }; +}; +exports.useUpdateCategory = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ + options, + endpoint, + requsetMethod: 'post' + }); + return { data, loading, error }; +}; +exports.useDeleteCategory = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ + options, + endpoint, + requsetMethod: 'delete' + }); + return { data, loading, error }; +}; + + +/***/ }), + +/***/ "./src/hooks/useComments.tsx": +/*!***********************************!*\ + !*** ./src/hooks/useComments.tsx ***! + \***********************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", { value: true }); +const useApiRequest_1 = __webpack_require__(/*! ./useApiRequest */ "./src/hooks/useApiRequest.tsx"); +const endpoint = 'comments'; +exports.useComments = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint }); + return { data, loading, error }; +}; +exports.useCreateComment = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ + options, + endpoint, + requsetMethod: 'post' + }); + return { data, loading, error }; +}; +exports.useRetriveComment = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint }); + return { data, loading, error }; +}; +exports.useUpdateComment = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ + options, + endpoint, + requsetMethod: 'post' + }); + return { data, loading, error }; +}; +exports.useDeleteComment = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ + options, + endpoint, + requsetMethod: 'delete' + }); + return { data, loading, error }; +}; + + +/***/ }), + +/***/ "./src/hooks/useMedia.tsx": +/*!********************************!*\ + !*** ./src/hooks/useMedia.tsx ***! + \********************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", { value: true }); +const useApiRequest_1 = __webpack_require__(/*! ./useApiRequest */ "./src/hooks/useApiRequest.tsx"); +const endpoint = 'media'; +exports.useMedia = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint }); + return { data, loading, error }; +}; +exports.useCreateMedia = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ + options, + endpoint, + requsetMethod: 'post' + }); + return { data, loading, error }; +}; +exports.useRetriveMedia = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint }); + return { data, loading, error }; +}; +exports.useUpdateMedia = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ + options, + endpoint, + requsetMethod: 'post' + }); + return { data, loading, error }; +}; +exports.useDeleteMedia = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ + options, + endpoint, + requsetMethod: 'delete' + }); + return { data, loading, error }; +}; + + +/***/ }), + +/***/ "./src/hooks/usePages.tsx": +/*!********************************!*\ + !*** ./src/hooks/usePages.tsx ***! + \********************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", { value: true }); +const useApiRequest_1 = __webpack_require__(/*! ./useApiRequest */ "./src/hooks/useApiRequest.tsx"); +const endpoint = 'pages'; +exports.usePages = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint }); + return { data, loading, error }; +}; +exports.useCreatePage = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ + options, + endpoint, + requsetMethod: 'post' + }); + return { data, loading, error }; +}; +exports.useRetrivePage = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint }); + return { data, loading, error }; +}; +exports.useUpdatePage = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ + options, + endpoint, + requsetMethod: 'post' + }); + return { data, loading, error }; +}; +exports.useDeletePage = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ + options, + endpoint, + requsetMethod: 'delete' + }); + return { data, loading, error }; +}; + + +/***/ }), + +/***/ "./src/hooks/usePosts.tsx": +/*!********************************!*\ + !*** ./src/hooks/usePosts.tsx ***! + \********************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", { value: true }); +const useApiRequest_1 = __webpack_require__(/*! ./useApiRequest */ "./src/hooks/useApiRequest.tsx"); +const endpoint = 'posts'; +exports.usePosts = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint }); + return { data, loading, error }; +}; +exports.useCreatePost = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ + options, + endpoint, + requsetMethod: 'post' + }); + return { data, loading, error }; +}; +exports.useRetrivePost = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint }); + return { data, loading, error }; +}; +exports.useUpdatePost = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint }); + return { data, loading, error }; +}; +exports.useDeletePost = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ + options, + endpoint, + requsetMethod: 'delete' + }); + return { data, loading, error }; +}; + + +/***/ }), + +/***/ "./src/hooks/useRevisions.tsx": +/*!************************************!*\ + !*** ./src/hooks/useRevisions.tsx ***! + \************************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", { value: true }); +const useApiRequest_1 = __webpack_require__(/*! ./useApiRequest */ "./src/hooks/useApiRequest.tsx"); +const endpoint = 'revisions'; +exports.useRevisions = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ + options, + endpoint, + requsetMethod: 'delete' + }); + return { data, loading, error }; +}; +exports.useRetriveRevision = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint }); + return { data, loading, error }; +}; +exports.useDeleteRevision = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ + options, + endpoint, + requsetMethod: 'delete' + }); + return { data, loading, error }; +}; + + +/***/ }), + +/***/ "./src/hooks/useSettings.tsx": +/*!***********************************!*\ + !*** ./src/hooks/useSettings.tsx ***! + \***********************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", { value: true }); +const useApiRequest_1 = __webpack_require__(/*! ./useApiRequest */ "./src/hooks/useApiRequest.tsx"); +const endpoint = 'settings'; +exports.useSettings = () => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ endpoint }); + return { data, loading, error }; +}; +exports.useUpdateSetting = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ + options, + endpoint, + requsetMethod: 'post' + }); + return { data, loading, error }; +}; + + +/***/ }), + +/***/ "./src/hooks/useStatuses.tsx": +/*!***********************************!*\ + !*** ./src/hooks/useStatuses.tsx ***! + \***********************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", { value: true }); +const useApiRequest_1 = __webpack_require__(/*! ./useApiRequest */ "./src/hooks/useApiRequest.tsx"); +const endpoint = 'statuses'; +exports.useStatuses = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint }); + return { data, loading, error }; +}; +exports.useRetriveStatus = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint }); + return { data, loading, error }; +}; + + +/***/ }), + +/***/ "./src/hooks/useTags.tsx": +/*!*******************************!*\ + !*** ./src/hooks/useTags.tsx ***! + \*******************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", { value: true }); +const useApiRequest_1 = __webpack_require__(/*! ./useApiRequest */ "./src/hooks/useApiRequest.tsx"); +const endpoint = 'tags'; +exports.useTags = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint }); + return { data, loading, error }; +}; +exports.useCreateTag = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ + options, + endpoint, + requsetMethod: 'post' + }); + return { data, loading, error }; +}; +exports.useRetriveTag = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint }); + return { data, loading, error }; +}; +exports.useUpdateTag = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ + options, + endpoint, + requsetMethod: 'post' + }); + return { data, loading, error }; +}; +exports.useDeleteTag = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ + options, + endpoint, + requsetMethod: 'delete' + }); + return { data, loading, error }; +}; + + +/***/ }), + +/***/ "./src/hooks/useTaxonomies.tsx": +/*!*************************************!*\ + !*** ./src/hooks/useTaxonomies.tsx ***! + \*************************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", { value: true }); +const useApiRequest_1 = __webpack_require__(/*! ./useApiRequest */ "./src/hooks/useApiRequest.tsx"); +const endpoint = 'taxonomies'; +exports.useTaxonomies = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint }); + return { data, loading, error }; +}; +exports.useRetriveTaxonomy = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint }); + return { data, loading, error }; +}; + + +/***/ }), + +/***/ "./src/hooks/useTypes.tsx": +/*!********************************!*\ + !*** ./src/hooks/useTypes.tsx ***! + \********************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", { value: true }); +const useApiRequest_1 = __webpack_require__(/*! ./useApiRequest */ "./src/hooks/useApiRequest.tsx"); +const endpoint = 'types'; +exports.useTypes = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint }); + return { data, loading, error }; +}; +exports.useRetriveType = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint }); + return { data, loading, error }; +}; + + +/***/ }), + +/***/ "./src/hooks/useUsers.tsx": +/*!********************************!*\ + !*** ./src/hooks/useUsers.tsx ***! + \********************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", { value: true }); +const useApiRequest_1 = __webpack_require__(/*! ./useApiRequest */ "./src/hooks/useApiRequest.tsx"); +const endpoint = 'users'; +exports.useUsers = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint }); + return { data, loading, error }; +}; +exports.useCreateUser = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ + options, + endpoint, + requsetMethod: 'post' + }); + return { data, loading, error }; +}; +exports.useRetriveUser = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint }); + return { data, loading, error }; +}; +exports.useUpdateUser = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ + options, + endpoint, + requsetMethod: 'post' + }); + return { data, loading, error }; +}; +exports.useDeleteUser = (options) => { + const { data, loading, error } = useApiRequest_1.useApiRequest({ + options, + endpoint, + requsetMethod: 'delete' + }); + return { data, loading, error }; +}; + + +/***/ }), + +/***/ "./src/index.tsx": +/*!***********************!*\ + !*** ./src/index.tsx ***! + \***********************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", { value: true }); +var usePosts_1 = __webpack_require__(/*! ./hooks/usePosts */ "./src/hooks/usePosts.tsx"); +exports.usePosts = usePosts_1.usePosts; +exports.useCreatePost = usePosts_1.useCreatePost; +exports.useRetrivePost = usePosts_1.useRetrivePost; +exports.useUpdatePost = usePosts_1.useUpdatePost; +exports.useDeletePost = usePosts_1.useDeletePost; +var useRevisions_1 = __webpack_require__(/*! ./hooks/useRevisions */ "./src/hooks/useRevisions.tsx"); +exports.useRevisions = useRevisions_1.useRevisions; +exports.useRetriveRevision = useRevisions_1.useRetriveRevision; +exports.useDeleteRevision = useRevisions_1.useDeleteRevision; +var useCategories_1 = __webpack_require__(/*! ./hooks/useCategories */ "./src/hooks/useCategories.tsx"); +exports.useCategories = useCategories_1.useCategories; +exports.useCreateCategory = useCategories_1.useCreateCategory; +exports.useRetriveCategory = useCategories_1.useRetriveCategory; +exports.useUpdateCategory = useCategories_1.useUpdateCategory; +exports.useDeleteCategory = useCategories_1.useDeleteCategory; +var useTags_1 = __webpack_require__(/*! ./hooks/useTags */ "./src/hooks/useTags.tsx"); +exports.useTags = useTags_1.useTags; +exports.useCreateTag = useTags_1.useCreateTag; +exports.useRetriveTag = useTags_1.useRetriveTag; +exports.useUpdateTag = useTags_1.useUpdateTag; +exports.useDeleteTag = useTags_1.useDeleteTag; +var usePages_1 = __webpack_require__(/*! ./hooks/usePages */ "./src/hooks/usePages.tsx"); +exports.usePages = usePages_1.usePages; +exports.useCreatePage = usePages_1.useCreatePage; +exports.useRetrivePage = usePages_1.useRetrivePage; +exports.useUpdatePage = usePages_1.useUpdatePage; +exports.useDeletePage = usePages_1.useDeletePage; +var useComments_1 = __webpack_require__(/*! ./hooks/useComments */ "./src/hooks/useComments.tsx"); +exports.useComments = useComments_1.useComments; +exports.useCreateComment = useComments_1.useCreateComment; +exports.useRetriveComment = useComments_1.useRetriveComment; +exports.useUpdateComment = useComments_1.useUpdateComment; +exports.useDeleteComment = useComments_1.useDeleteComment; +var useTaxonomies_1 = __webpack_require__(/*! ./hooks/useTaxonomies */ "./src/hooks/useTaxonomies.tsx"); +exports.useTaxonomies = useTaxonomies_1.useTaxonomies; +exports.useRetriveTaxonomy = useTaxonomies_1.useRetriveTaxonomy; +var useMedia_1 = __webpack_require__(/*! ./hooks/useMedia */ "./src/hooks/useMedia.tsx"); +exports.useMedia = useMedia_1.useMedia; +exports.useCreateMedia = useMedia_1.useCreateMedia; +exports.useRetriveMedia = useMedia_1.useRetriveMedia; +exports.useUpdateMedia = useMedia_1.useUpdateMedia; +exports.useDeleteMedia = useMedia_1.useDeleteMedia; +var useUsers_1 = __webpack_require__(/*! ./hooks/useUsers */ "./src/hooks/useUsers.tsx"); +exports.useUsers = useUsers_1.useUsers; +exports.useCreateUser = useUsers_1.useCreateUser; +exports.useRetriveUser = useUsers_1.useRetriveUser; +exports.useUpdateUser = useUsers_1.useUpdateUser; +exports.useDeleteUser = useUsers_1.useDeleteUser; +var useTypes_1 = __webpack_require__(/*! ./hooks/useTypes */ "./src/hooks/useTypes.tsx"); +exports.useTypes = useTypes_1.useTypes; +exports.useRetriveType = useTypes_1.useRetriveType; +var useStatuses_1 = __webpack_require__(/*! ./hooks/useStatuses */ "./src/hooks/useStatuses.tsx"); +exports.useStatuses = useStatuses_1.useStatuses; +exports.useRetriveStatus = useStatuses_1.useRetriveStatus; +var useSettings_1 = __webpack_require__(/*! ./hooks/useSettings */ "./src/hooks/useSettings.tsx"); +exports.useSettings = useSettings_1.useSettings; +exports.useUpdateSetting = useSettings_1.useUpdateSetting; +var context_1 = __webpack_require__(/*! ./context */ "./src/context.tsx"); +exports.WPContext = context_1.WPContext; + + +/***/ }), + +/***/ "./src/utils/index.tsx": +/*!*****************************!*\ + !*** ./src/utils/index.tsx ***! + \*****************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", { value: true }); +exports.serialize = (object) => { + const string = []; + for (let key in object) { + if (object.hasOwnProperty(key)) { + string.push(`${encodeURIComponent(key)}=${encodeURIComponent(object[key])}`); + } + } + return string.length > 0 ? '?' + string.join('&') : ''; +}; + + +/***/ }), + +/***/ "react": +/*!************************!*\ + !*** external "react" ***! + \************************/ +/*! no static exports found */ +/***/ (function(module, exports) { + +module.exports = require("react"); + +/***/ }) + +/******/ }); +//# sourceMappingURL=react-wordpress-hooks.js.map \ No newline at end of file diff --git a/lib/react-wordpress-hooks.js.map b/lib/react-wordpress-hooks.js.map new file mode 100644 index 0000000..4344c72 --- /dev/null +++ b/lib/react-wordpress-hooks.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["webpack://ReactWPHooks/webpack/bootstrap","webpack://ReactWPHooks/./src/context.tsx","webpack://ReactWPHooks/./src/hooks/useApiRequest.tsx","webpack://ReactWPHooks/./src/hooks/useCategories.tsx","webpack://ReactWPHooks/./src/hooks/useComments.tsx","webpack://ReactWPHooks/./src/hooks/useMedia.tsx","webpack://ReactWPHooks/./src/hooks/usePages.tsx","webpack://ReactWPHooks/./src/hooks/usePosts.tsx","webpack://ReactWPHooks/./src/hooks/useRevisions.tsx","webpack://ReactWPHooks/./src/hooks/useSettings.tsx","webpack://ReactWPHooks/./src/hooks/useStatuses.tsx","webpack://ReactWPHooks/./src/hooks/useTags.tsx","webpack://ReactWPHooks/./src/hooks/useTaxonomies.tsx","webpack://ReactWPHooks/./src/hooks/useTypes.tsx","webpack://ReactWPHooks/./src/hooks/useUsers.tsx","webpack://ReactWPHooks/./src/index.tsx","webpack://ReactWPHooks/./src/utils/index.tsx","webpack://ReactWPHooks/external \"react\""],"names":[],"mappings":";;AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,kDAA0C,gCAAgC;AAC1E;AACA;;AAEA;AACA;AACA;AACA,gEAAwD,kBAAkB;AAC1E;AACA,yDAAiD,cAAc;AAC/D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iDAAyC,iCAAiC;AAC1E,wHAAgH,mBAAmB,EAAE;AACrI;AACA;;AAEA;AACA;AACA;AACA,mCAA2B,0BAA0B,EAAE;AACvD,yCAAiC,eAAe;AAChD;AACA;AACA;;AAEA;AACA,8DAAsD,+DAA+D;;AAErH;AACA;;;AAGA;AACA;;;;;;;;;;;;;AClFa;AACb;AACA,4CAA4C;AAC5C;AACA,8CAA8C,cAAc;AAC5D,gCAAgC,mBAAO,CAAC,oBAAO;AAC/C;AACA;AACA;A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B;AAC3C;AACA;AACA;AACA;AACA;AACA,oBAAoB,mBAAO,CAAC,wDAAqB;AACjD;AACA;AACA;AACA;AACA;AACA,sBAAsB,mBAAO,CAAC,4DAAuB;AACrD;AACA;AACA,iBAAiB,mBAAO,CAAC,kDAAkB;AAC3C;AACA;AACA;AACA;AACA;AACA,iBAAiB,mBAAO,CAAC,kDAAkB;AAC3C;AACA;AACA;AACA;AACA;AACA,iBAAiB,mBAAO,CAAC,kDAAkB;AAC3C;AACA;AACA,oBAAoB,mBAAO,CAAC,wDAAqB;AACjD;AACA;AACA,oBAAoB,mBAAO,CAAC,wDAAqB;AACjD;AACA;AACA,gBAAgB,mBAAO,CAAC,oCAAW;AACnC;;;;;;;;;;;;;AC7Da;AACb,8CAA8C,cAAc;AAC5D;AACA;AACA;AACA;AACA,2BAA2B,wBAAwB,GAAG,gCAAgC;AACtF;AACA;AACA;AACA;;;;;;;;;;;;ACVA,kC","file":"react-wordpress-hooks.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = \"./src/index.tsx\");\n","\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst react_1 = __importDefault(require(\"react\"));\nexports.WPContext = react_1.default.createContext({\n url: '',\n auth: {\n email: '',\n password: ''\n }\n});\n","\"use strict\";\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst react_1 = require(\"react\");\nconst context_1 = require(\"../context\");\nconst utils_1 = require(\"../utils\");\nexports.useApiRequest = ({ options, requsetMethod = 'get', endpoint = '' }) => {\n const { url, auth } = react_1.useContext(context_1.WPContext);\n const [data, setData] = react_1.useState([]);\n const [loading, setLoading] = react_1.useState(false);\n const [error, setError] = react_1.useState(null);\n react_1.useEffect(() => {\n const loadData = () => __awaiter(this, void 0, void 0, function* () {\n try {\n setLoading(true);\n const res = yield fetch(`${url}/wp-json/wp/v2${endpoint ? `/${endpoint}` : ''}${typeof options === 'number' && requsetMethod === 'get'\n ? `/${options}`\n : utils_1.serialize(options)}`, {\n method: requsetMethod,\n headers: {\n Authorization: `Basic ${btoa(`${auth.email}:${auth.password}`)}`\n }\n });\n const response = yield res.json();\n setLoading(false);\n if (response.code) {\n setError(response);\n }\n else {\n setData(response);\n }\n }\n catch (err) {\n setLoading(false);\n setError(err);\n }\n });\n loadData();\n }, [auth.email, auth.password, endpoint, options, requsetMethod, url]);\n return { data, loading, error };\n};\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst useApiRequest_1 = require(\"./useApiRequest\");\nconst endpoint = 'categories';\nexports.useCategories = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({\n options,\n endpoint\n });\n return { data, loading, error };\n};\nexports.useCreateCategory = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({\n options,\n endpoint,\n requsetMethod: 'post'\n });\n return { data, loading, error };\n};\nexports.useRetriveCategory = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({\n options,\n endpoint\n });\n return { data, loading, error };\n};\nexports.useUpdateCategory = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({\n options,\n endpoint,\n requsetMethod: 'post'\n });\n return { data, loading, error };\n};\nexports.useDeleteCategory = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({\n options,\n endpoint,\n requsetMethod: 'delete'\n });\n return { data, loading, error };\n};\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst useApiRequest_1 = require(\"./useApiRequest\");\nconst endpoint = 'comments';\nexports.useComments = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint });\n return { data, loading, error };\n};\nexports.useCreateComment = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({\n options,\n endpoint,\n requsetMethod: 'post'\n });\n return { data, loading, error };\n};\nexports.useRetriveComment = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint });\n return { data, loading, error };\n};\nexports.useUpdateComment = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({\n options,\n endpoint,\n requsetMethod: 'post'\n });\n return { data, loading, error };\n};\nexports.useDeleteComment = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({\n options,\n endpoint,\n requsetMethod: 'delete'\n });\n return { data, loading, error };\n};\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst useApiRequest_1 = require(\"./useApiRequest\");\nconst endpoint = 'media';\nexports.useMedia = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint });\n return { data, loading, error };\n};\nexports.useCreateMedia = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({\n options,\n endpoint,\n requsetMethod: 'post'\n });\n return { data, loading, error };\n};\nexports.useRetriveMedia = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint });\n return { data, loading, error };\n};\nexports.useUpdateMedia = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({\n options,\n endpoint,\n requsetMethod: 'post'\n });\n return { data, loading, error };\n};\nexports.useDeleteMedia = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({\n options,\n endpoint,\n requsetMethod: 'delete'\n });\n return { data, loading, error };\n};\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst useApiRequest_1 = require(\"./useApiRequest\");\nconst endpoint = 'pages';\nexports.usePages = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint });\n return { data, loading, error };\n};\nexports.useCreatePage = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({\n options,\n endpoint,\n requsetMethod: 'post'\n });\n return { data, loading, error };\n};\nexports.useRetrivePage = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint });\n return { data, loading, error };\n};\nexports.useUpdatePage = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({\n options,\n endpoint,\n requsetMethod: 'post'\n });\n return { data, loading, error };\n};\nexports.useDeletePage = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({\n options,\n endpoint,\n requsetMethod: 'delete'\n });\n return { data, loading, error };\n};\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst useApiRequest_1 = require(\"./useApiRequest\");\nconst endpoint = 'posts';\nexports.usePosts = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint });\n return { data, loading, error };\n};\nexports.useCreatePost = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({\n options,\n endpoint,\n requsetMethod: 'post'\n });\n return { data, loading, error };\n};\nexports.useRetrivePost = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint });\n return { data, loading, error };\n};\nexports.useUpdatePost = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint });\n return { data, loading, error };\n};\nexports.useDeletePost = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({\n options,\n endpoint,\n requsetMethod: 'delete'\n });\n return { data, loading, error };\n};\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst useApiRequest_1 = require(\"./useApiRequest\");\nconst endpoint = 'revisions';\nexports.useRevisions = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({\n options,\n endpoint,\n requsetMethod: 'delete'\n });\n return { data, loading, error };\n};\nexports.useRetriveRevision = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint });\n return { data, loading, error };\n};\nexports.useDeleteRevision = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({\n options,\n endpoint,\n requsetMethod: 'delete'\n });\n return { data, loading, error };\n};\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst useApiRequest_1 = require(\"./useApiRequest\");\nconst endpoint = 'settings';\nexports.useSettings = () => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({ endpoint });\n return { data, loading, error };\n};\nexports.useUpdateSetting = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({\n options,\n endpoint,\n requsetMethod: 'post'\n });\n return { data, loading, error };\n};\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst useApiRequest_1 = require(\"./useApiRequest\");\nconst endpoint = 'statuses';\nexports.useStatuses = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint });\n return { data, loading, error };\n};\nexports.useRetriveStatus = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint });\n return { data, loading, error };\n};\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst useApiRequest_1 = require(\"./useApiRequest\");\nconst endpoint = 'tags';\nexports.useTags = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint });\n return { data, loading, error };\n};\nexports.useCreateTag = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({\n options,\n endpoint,\n requsetMethod: 'post'\n });\n return { data, loading, error };\n};\nexports.useRetriveTag = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint });\n return { data, loading, error };\n};\nexports.useUpdateTag = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({\n options,\n endpoint,\n requsetMethod: 'post'\n });\n return { data, loading, error };\n};\nexports.useDeleteTag = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({\n options,\n endpoint,\n requsetMethod: 'delete'\n });\n return { data, loading, error };\n};\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst useApiRequest_1 = require(\"./useApiRequest\");\nconst endpoint = 'taxonomies';\nexports.useTaxonomies = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint });\n return { data, loading, error };\n};\nexports.useRetriveTaxonomy = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint });\n return { data, loading, error };\n};\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst useApiRequest_1 = require(\"./useApiRequest\");\nconst endpoint = 'types';\nexports.useTypes = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint });\n return { data, loading, error };\n};\nexports.useRetriveType = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint });\n return { data, loading, error };\n};\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst useApiRequest_1 = require(\"./useApiRequest\");\nconst endpoint = 'users';\nexports.useUsers = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint });\n return { data, loading, error };\n};\nexports.useCreateUser = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({\n options,\n endpoint,\n requsetMethod: 'post'\n });\n return { data, loading, error };\n};\nexports.useRetriveUser = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({ options, endpoint });\n return { data, loading, error };\n};\nexports.useUpdateUser = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({\n options,\n endpoint,\n requsetMethod: 'post'\n });\n return { data, loading, error };\n};\nexports.useDeleteUser = (options) => {\n const { data, loading, error } = useApiRequest_1.useApiRequest({\n options,\n endpoint,\n requsetMethod: 'delete'\n });\n return { data, loading, error };\n};\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar usePosts_1 = require(\"./hooks/usePosts\");\nexports.usePosts = usePosts_1.usePosts;\nexports.useCreatePost = usePosts_1.useCreatePost;\nexports.useRetrivePost = usePosts_1.useRetrivePost;\nexports.useUpdatePost = usePosts_1.useUpdatePost;\nexports.useDeletePost = usePosts_1.useDeletePost;\nvar useRevisions_1 = require(\"./hooks/useRevisions\");\nexports.useRevisions = useRevisions_1.useRevisions;\nexports.useRetriveRevision = useRevisions_1.useRetriveRevision;\nexports.useDeleteRevision = useRevisions_1.useDeleteRevision;\nvar useCategories_1 = require(\"./hooks/useCategories\");\nexports.useCategories = useCategories_1.useCategories;\nexports.useCreateCategory = useCategories_1.useCreateCategory;\nexports.useRetriveCategory = useCategories_1.useRetriveCategory;\nexports.useUpdateCategory = useCategories_1.useUpdateCategory;\nexports.useDeleteCategory = useCategories_1.useDeleteCategory;\nvar useTags_1 = require(\"./hooks/useTags\");\nexports.useTags = useTags_1.useTags;\nexports.useCreateTag = useTags_1.useCreateTag;\nexports.useRetriveTag = useTags_1.useRetriveTag;\nexports.useUpdateTag = useTags_1.useUpdateTag;\nexports.useDeleteTag = useTags_1.useDeleteTag;\nvar usePages_1 = require(\"./hooks/usePages\");\nexports.usePages = usePages_1.usePages;\nexports.useCreatePage = usePages_1.useCreatePage;\nexports.useRetrivePage = usePages_1.useRetrivePage;\nexports.useUpdatePage = usePages_1.useUpdatePage;\nexports.useDeletePage = usePages_1.useDeletePage;\nvar useComments_1 = require(\"./hooks/useComments\");\nexports.useComments = useComments_1.useComments;\nexports.useCreateComment = useComments_1.useCreateComment;\nexports.useRetriveComment = useComments_1.useRetriveComment;\nexports.useUpdateComment = useComments_1.useUpdateComment;\nexports.useDeleteComment = useComments_1.useDeleteComment;\nvar useTaxonomies_1 = require(\"./hooks/useTaxonomies\");\nexports.useTaxonomies = useTaxonomies_1.useTaxonomies;\nexports.useRetriveTaxonomy = useTaxonomies_1.useRetriveTaxonomy;\nvar useMedia_1 = require(\"./hooks/useMedia\");\nexports.useMedia = useMedia_1.useMedia;\nexports.useCreateMedia = useMedia_1.useCreateMedia;\nexports.useRetriveMedia = useMedia_1.useRetriveMedia;\nexports.useUpdateMedia = useMedia_1.useUpdateMedia;\nexports.useDeleteMedia = useMedia_1.useDeleteMedia;\nvar useUsers_1 = require(\"./hooks/useUsers\");\nexports.useUsers = useUsers_1.useUsers;\nexports.useCreateUser = useUsers_1.useCreateUser;\nexports.useRetriveUser = useUsers_1.useRetriveUser;\nexports.useUpdateUser = useUsers_1.useUpdateUser;\nexports.useDeleteUser = useUsers_1.useDeleteUser;\nvar useTypes_1 = require(\"./hooks/useTypes\");\nexports.useTypes = useTypes_1.useTypes;\nexports.useRetriveType = useTypes_1.useRetriveType;\nvar useStatuses_1 = require(\"./hooks/useStatuses\");\nexports.useStatuses = useStatuses_1.useStatuses;\nexports.useRetriveStatus = useStatuses_1.useRetriveStatus;\nvar useSettings_1 = require(\"./hooks/useSettings\");\nexports.useSettings = useSettings_1.useSettings;\nexports.useUpdateSetting = useSettings_1.useUpdateSetting;\nvar context_1 = require(\"./context\");\nexports.WPContext = context_1.WPContext;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.serialize = (object) => {\n const string = [];\n for (let key in object) {\n if (object.hasOwnProperty(key)) {\n string.push(`${encodeURIComponent(key)}=${encodeURIComponent(object[key])}`);\n }\n }\n return string.length > 0 ? '?' + string.join('&') : '';\n};\n","module.exports = require(\"react\");"],"sourceRoot":""} \ No newline at end of file diff --git a/lib/react-wordpress-hooks.min.js b/lib/react-wordpress-hooks.min.js new file mode 100644 index 0000000..7a6374c --- /dev/null +++ b/lib/react-wordpress-hooks.min.js @@ -0,0 +1 @@ +module.exports=function(e){var t={};function o(r){if(t[r])return t[r].exports;var s=t[r]={i:r,l:!1,exports:{}};return e[r].call(s.exports,s,s.exports,o),s.l=!0,s.exports}return o.m=e,o.c=t,o.d=function(e,t,r){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(o.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)o.d(r,s,function(t){return e[t]}.bind(null,s));return r},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="",o(o.s=3)}([function(e,t,o){"use strict";var r=this&&this.__awaiter||function(e,t,o,r){return new(o||(o=Promise))(function(s,n){function a(e){try{i(r.next(e))}catch(e){n(e)}}function u(e){try{i(r.throw(e))}catch(e){n(e)}}function i(e){e.done?s(e.value):new o(function(t){t(e.value)}).then(a,u)}i((r=r.apply(e,t||[])).next())})};Object.defineProperty(t,"__esModule",{value:!0});const s=o(1),n=o(2),a=o(5);t.useApiRequest=(({options:e,requsetMethod:t="get",endpoint:o=""})=>{const{url:u,auth:i}=s.useContext(n.WPContext),[d,p]=s.useState([]),[l,g]=s.useState(!1),[c,R]=s.useState(null);return s.useEffect(()=>{(()=>r(this,void 0,void 0,function*(){try{g(!0);const r=yield fetch(`${u}/wp-json/wp/v2${o?`/${o}`:""}${"number"==typeof e&&"get"===t?`/${e}`:a.serialize(e)}`,{method:t,headers:{Authorization:`Basic ${btoa(`${i.email}:${i.password}`)}`}}),s=yield r.json();g(!1),s.code?R(s):p(s)}catch(e){g(!1),R(e)}}))()},[i.email,i.password,o,e,t,u]),{data:d,loading:l,error:c}})},function(e,t){e.exports=require("react")},function(e,t,o){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=r(o(1));t.WPContext=s.default.createContext({url:"",auth:{email:"",password:""}})},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=o(4);t.usePosts=r.usePosts,t.useCreatePost=r.useCreatePost,t.useRetrivePost=r.useRetrivePost,t.useUpdatePost=r.useUpdatePost,t.useDeletePost=r.useDeletePost;var s=o(6);t.useRevisions=s.useRevisions,t.useRetriveRevision=s.useRetriveRevision,t.useDeleteRevision=s.useDeleteRevision;var n=o(7);t.useCategories=n.useCategories,t.useCreateCategory=n.useCreateCategory,t.useRetriveCategory=n.useRetriveCategory,t.useUpdateCategory=n.useUpdateCategory,t.useDeleteCategory=n.useDeleteCategory;var a=o(8);t.useTags=a.useTags,t.useCreateTag=a.useCreateTag,t.useRetriveTag=a.useRetriveTag,t.useUpdateTag=a.useUpdateTag,t.useDeleteTag=a.useDeleteTag;var u=o(9);t.usePages=u.usePages,t.useCreatePage=u.useCreatePage,t.useRetrivePage=u.useRetrivePage,t.useUpdatePage=u.useUpdatePage,t.useDeletePage=u.useDeletePage;var i=o(10);t.useComments=i.useComments,t.useCreateComment=i.useCreateComment,t.useRetriveComment=i.useRetriveComment,t.useUpdateComment=i.useUpdateComment,t.useDeleteComment=i.useDeleteComment;var d=o(11);t.useTaxonomies=d.useTaxonomies,t.useRetriveTaxonomy=d.useRetriveTaxonomy;var p=o(12);t.useMedia=p.useMedia,t.useCreateMedia=p.useCreateMedia,t.useRetriveMedia=p.useRetriveMedia,t.useUpdateMedia=p.useUpdateMedia,t.useDeleteMedia=p.useDeleteMedia;var l=o(13);t.useUsers=l.useUsers,t.useCreateUser=l.useCreateUser,t.useRetriveUser=l.useRetriveUser,t.useUpdateUser=l.useUpdateUser,t.useDeleteUser=l.useDeleteUser;var g=o(14);t.useTypes=g.useTypes,t.useRetriveType=g.useRetriveType;var c=o(15);t.useStatuses=c.useStatuses,t.useRetriveStatus=c.useRetriveStatus;var R=o(16);t.useSettings=R.useSettings,t.useUpdateSetting=R.useUpdateSetting;var v=o(2);t.WPContext=v.WPContext},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const r=o(0);t.usePosts=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"posts"});return{data:t,loading:o,error:s}}),t.useCreatePost=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"posts",requsetMethod:"post"});return{data:t,loading:o,error:s}}),t.useRetrivePost=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"posts"});return{data:t,loading:o,error:s}}),t.useUpdatePost=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"posts"});return{data:t,loading:o,error:s}}),t.useDeletePost=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"posts",requsetMethod:"delete"});return{data:t,loading:o,error:s}})},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.serialize=(e=>{const t=[];for(let o in e)e.hasOwnProperty(o)&&t.push(`${encodeURIComponent(o)}=${encodeURIComponent(e[o])}`);return t.length>0?"?"+t.join("&"):""})},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const r=o(0);t.useRevisions=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"revisions",requsetMethod:"delete"});return{data:t,loading:o,error:s}}),t.useRetriveRevision=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"revisions"});return{data:t,loading:o,error:s}}),t.useDeleteRevision=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"revisions",requsetMethod:"delete"});return{data:t,loading:o,error:s}})},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const r=o(0);t.useCategories=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"categories"});return{data:t,loading:o,error:s}}),t.useCreateCategory=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"categories",requsetMethod:"post"});return{data:t,loading:o,error:s}}),t.useRetriveCategory=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"categories"});return{data:t,loading:o,error:s}}),t.useUpdateCategory=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"categories",requsetMethod:"post"});return{data:t,loading:o,error:s}}),t.useDeleteCategory=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"categories",requsetMethod:"delete"});return{data:t,loading:o,error:s}})},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const r=o(0);t.useTags=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"tags"});return{data:t,loading:o,error:s}}),t.useCreateTag=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"tags",requsetMethod:"post"});return{data:t,loading:o,error:s}}),t.useRetriveTag=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"tags"});return{data:t,loading:o,error:s}}),t.useUpdateTag=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"tags",requsetMethod:"post"});return{data:t,loading:o,error:s}}),t.useDeleteTag=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"tags",requsetMethod:"delete"});return{data:t,loading:o,error:s}})},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const r=o(0);t.usePages=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"pages"});return{data:t,loading:o,error:s}}),t.useCreatePage=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"pages",requsetMethod:"post"});return{data:t,loading:o,error:s}}),t.useRetrivePage=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"pages"});return{data:t,loading:o,error:s}}),t.useUpdatePage=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"pages",requsetMethod:"post"});return{data:t,loading:o,error:s}}),t.useDeletePage=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"pages",requsetMethod:"delete"});return{data:t,loading:o,error:s}})},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const r=o(0);t.useComments=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"comments"});return{data:t,loading:o,error:s}}),t.useCreateComment=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"comments",requsetMethod:"post"});return{data:t,loading:o,error:s}}),t.useRetriveComment=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"comments"});return{data:t,loading:o,error:s}}),t.useUpdateComment=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"comments",requsetMethod:"post"});return{data:t,loading:o,error:s}}),t.useDeleteComment=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"comments",requsetMethod:"delete"});return{data:t,loading:o,error:s}})},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const r=o(0);t.useTaxonomies=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"taxonomies"});return{data:t,loading:o,error:s}}),t.useRetriveTaxonomy=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"taxonomies"});return{data:t,loading:o,error:s}})},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const r=o(0);t.useMedia=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"media"});return{data:t,loading:o,error:s}}),t.useCreateMedia=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"media",requsetMethod:"post"});return{data:t,loading:o,error:s}}),t.useRetriveMedia=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"media"});return{data:t,loading:o,error:s}}),t.useUpdateMedia=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"media",requsetMethod:"post"});return{data:t,loading:o,error:s}}),t.useDeleteMedia=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"media",requsetMethod:"delete"});return{data:t,loading:o,error:s}})},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const r=o(0);t.useUsers=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"users"});return{data:t,loading:o,error:s}}),t.useCreateUser=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"users",requsetMethod:"post"});return{data:t,loading:o,error:s}}),t.useRetriveUser=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"users"});return{data:t,loading:o,error:s}}),t.useUpdateUser=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"users",requsetMethod:"post"});return{data:t,loading:o,error:s}}),t.useDeleteUser=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"users",requsetMethod:"delete"});return{data:t,loading:o,error:s}})},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const r=o(0);t.useTypes=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"types"});return{data:t,loading:o,error:s}}),t.useRetriveType=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"types"});return{data:t,loading:o,error:s}})},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const r=o(0);t.useStatuses=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"statuses"});return{data:t,loading:o,error:s}}),t.useRetriveStatus=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"statuses"});return{data:t,loading:o,error:s}})},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const r=o(0);t.useSettings=(()=>{const{data:e,loading:t,error:o}=r.useApiRequest({endpoint:"settings"});return{data:e,loading:t,error:o}}),t.useUpdateSetting=(e=>{const{data:t,loading:o,error:s}=r.useApiRequest({options:e,endpoint:"settings",requsetMethod:"post"});return{data:t,loading:o,error:s}})}]); \ No newline at end of file diff --git a/package.json b/package.json index 6171b5f..f0013a7 100755 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "homepage": "https://github.com/JB1905/react-wordpress-hooks#readme", "devDependencies": { "@types/react": "^16.8.19", - "@typescript-eslint/parser": "^1.9.0", + "@typescript-eslint/parser": "^1.10.2", "docz": "^1.2.0", "docz-theme-default": "^1.2.0", "eslint": "^5.16.0", @@ -44,14 +44,11 @@ "eslint-plugin-react": "^7.13.0", "eslint-plugin-react-hooks": "^1.6.0", "gh-pages": "^2.0.1", - "prettier": "^1.17.1", - "react": "^16.8.6", - "ts-loader": "^6.0.1", + "prettier": "^1.18.2", + "ts-loader": "^6.0.2", "typescript": "^3.5.1", - "webpack": "^4.32.2", - "webpack-cli": "^3.3.2" + "webpack": "^4.33.0", + "webpack-cli": "^3.3.4" }, - "peerDependencies": { - "react": ">=16.8.0" - } + "peerDependencies": {} } diff --git a/src/hooks/useApiRequest.tsx b/src/hooks/useApiRequest.tsx index c30a262..489cb8d 100644 --- a/src/hooks/useApiRequest.tsx +++ b/src/hooks/useApiRequest.tsx @@ -17,7 +17,7 @@ export const useApiRequest = ({ const [data, setData] = useState([]); const [loading, setLoading] = useState(false); - const [error, setError] = useState(false); + const [error, setError] = useState(null); useEffect(() => { const loadData = async () => { @@ -38,16 +38,23 @@ export const useApiRequest = ({ } ); - setData(await res.json()); + const response = await res.json(); + setLoading(false); - } catch { + + if (response.code) { + setError(response); + } else { + setData(response); + } + } catch (err) { setLoading(false); - setError(true); + setError(err); } }; loadData(); - }, [endpoint, options, requsetMethod, url]); + }, [auth.email, auth.password, endpoint, options, requsetMethod, url]); return { data, loading, error }; }; diff --git a/yarn.lock b/yarn.lock index f2325e6..b449e39 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1159,6 +1159,11 @@ prop-types "^15.6.2" tippy.js "^4.3.0" +"@types/eslint-visitor-keys@^1.0.0": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#1ee30d79544ca84d68d4b3cdb0af4f205663dd2d" + integrity sha512-OCutwjDZ4aFS6PB1UZ988C4YgwlBHJd6wCeQqaLdmadZ/7e+w79+hbMUFC1QXDNCmdyoRfAFdm0RypzwR+Qpag== + "@types/events@*": version "3.0.0" resolved "https://registry.yarnpkg.com/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7" @@ -1223,27 +1228,28 @@ "@types/unist" "*" "@types/vfile-message" "*" -"@typescript-eslint/experimental-utils@1.9.0": - version "1.9.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-1.9.0.tgz#a92777d0c92d7bc8627abd7cdb06cdbcaf2b39e8" - integrity sha512-1s2dY9XxBwtS9IlSnRIlzqILPyeMly5tz1bfAmQ84Ul687xBBve5YsH5A5EKeIcGurYYqY2w6RkHETXIwnwV0A== +"@typescript-eslint/experimental-utils@1.10.2": + version "1.10.2" + resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-1.10.2.tgz#cd548c03fc1a2b3ba5c136d1599001a1ede24215" + integrity sha512-Hf5lYcrnTH5Oc67SRrQUA7KuHErMvCf5RlZsyxXPIT6AXa8fKTyfFO6vaEnUmlz48RpbxO4f0fY3QtWkuHZNjg== dependencies: - "@typescript-eslint/typescript-estree" "1.9.0" + "@typescript-eslint/typescript-estree" "1.10.2" + eslint-scope "^4.0.0" -"@typescript-eslint/parser@^1.9.0": - version "1.9.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-1.9.0.tgz#5796cbfcb9a3a5757aeb671c1ac88d7a94a95962" - integrity sha512-CWgC1XrQ34H/+LwAU7vY5xteZDkNqeAkeidEpJnJgkKu0yqQ3ZhQ7S+dI6MX4vmmM1TKRbOrKuXc6W0fIHhdbA== +"@typescript-eslint/parser@^1.10.2": + version "1.10.2" + resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-1.10.2.tgz#36cfe8c6bf1b6c1dd81da56f88c8588f4b1a852b" + integrity sha512-xWDWPfZfV0ENU17ermIUVEVSseBBJxKfqBcRCMZ8nAjJbfA5R7NWMZmFFHYnars5MjK4fPjhu4gwQv526oZIPQ== dependencies: - "@typescript-eslint/experimental-utils" "1.9.0" - "@typescript-eslint/typescript-estree" "1.9.0" - eslint-scope "^4.0.0" + "@types/eslint-visitor-keys" "^1.0.0" + "@typescript-eslint/experimental-utils" "1.10.2" + "@typescript-eslint/typescript-estree" "1.10.2" eslint-visitor-keys "^1.0.0" -"@typescript-eslint/typescript-estree@1.9.0": - version "1.9.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-1.9.0.tgz#5d6d49be936e96fb0f859673480f89b070a5dd9b" - integrity sha512-7Eg0TEQpCkTsEwsl1lIzd6i7L3pJLQFWesV08dS87bNz0NeSjbL78gNAP1xCKaCejkds4PhpLnZkaAjx9SU8OA== +"@typescript-eslint/typescript-estree@1.10.2": + version "1.10.2" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-1.10.2.tgz#8403585dd74b6cfb6f78aa98b6958de158b5897b" + integrity sha512-Kutjz0i69qraOsWeI8ETqYJ07tRLvD9URmdrMoF10bG8y8ucLmPtSxROvVejWvlJUGl2et/plnMiKRDW+rhEhw== dependencies: lodash.unescape "4.0.1" semver "5.5.0" @@ -6824,11 +6830,16 @@ prettier-linter-helpers@^1.0.0: dependencies: fast-diff "^1.1.2" -prettier@^1.17.0, prettier@^1.17.1: +prettier@^1.17.0: version "1.17.1" resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.17.1.tgz#ed64b4e93e370cb8a25b9ef7fef3e4fd1c0995db" integrity sha512-TzGRNvuUSmPgwivDqkZ9tM/qTGW9hqDKWOE9YHiyQdixlKbv7kvEqsmDPrcHJTKwthU774TQwZXVtaQ/mMsvjg== +prettier@^1.18.2: + version "1.18.2" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.18.2.tgz#6823e7c5900017b4bd3acf46fe9ac4b4d7bda9ea" + integrity sha512-OeHeMc0JhFE9idD4ZdtNibzY0+TPHSpSSb9h8FqtP+YnoZZ1sl8Vc9b1sasjfymH3SonAF4QcA2+mzHPhMvIiw== + pretty-time@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/pretty-time/-/pretty-time-1.1.0.tgz#ffb7429afabb8535c346a34e41873adf3d74dd0e" @@ -8634,10 +8645,10 @@ tryer@^1.0.0: resolved "https://registry.yarnpkg.com/tryer/-/tryer-1.0.1.tgz#f2c85406800b9b0f74c9f7465b81eaad241252f8" integrity sha512-c3zayb8/kWWpycWYg87P71E1S1ZL6b6IJxfb5fvsUgsf0S2MVGaDhDXXjDMpdCpfWXqptc+4mXwmiy1ypXqRAA== -ts-loader@^6.0.1: - version "6.0.1" - resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-6.0.1.tgz#abe8ba59356da8cbc85c01ab5feb85ae998db315" - integrity sha512-9H5ErTIw5t73sdSoFE0hX0RO45B7cdDA4pW1VIQ2wNFAhxSpZcAlv2fwMcfv6SAYLoI7uGwHuzC5dECzmzqtzA== +ts-loader@^6.0.2: + version "6.0.2" + resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-6.0.2.tgz#cbd46a1495668ed9d59813f5c66f4bb49ff0c14c" + integrity sha512-kkF3sGf3oBUehlvXI9fkbItbFTnNgGkYAz91vtWnsKAU4m+LAmQjuby7uTZNo3As+/zHLuyB052SkQDY6vLXtg== dependencies: chalk "^2.3.0" enhanced-resolve "^4.0.0" @@ -9150,10 +9161,10 @@ webpack-chain@^6.0.0: deepmerge "^1.5.2" javascript-stringify "^2.0.0" -webpack-cli@^3.3.2: - version "3.3.2" - resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-3.3.2.tgz#aed2437b0db0a7faa2ad28484e166a5360014a91" - integrity sha512-FLkobnaJJ+03j5eplxlI0TUxhGCOdfewspIGuvDVtpOlrAuKMFC57K42Ukxqs1tn8947/PM6tP95gQc0DCzRYA== +webpack-cli@^3.3.4: + version "3.3.4" + resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-3.3.4.tgz#de27e281c48a897b8c219cb093e261d5f6afe44a" + integrity sha512-ubJGQEKMtBSpT+LiL5hXvn2GIOWiRWItR1DGUqJRhwRBeGhpRXjvF5f0erqdRJLErkfqS5/Ldkkedh4AL5Q1ZQ== dependencies: chalk "^2.4.1" cross-spawn "^6.0.5" @@ -9163,6 +9174,7 @@ webpack-cli@^3.3.2: import-local "^2.0.0" interpret "^1.1.0" loader-utils "^1.1.0" + prettier "^1.17.0" supports-color "^5.5.0" v8-compile-cache "^2.0.2" yargs "^12.0.5" @@ -9262,7 +9274,7 @@ webpack-sources@^1.1.0, webpack-sources@^1.3.0: source-list-map "^2.0.0" source-map "~0.6.1" -webpack@^4.30.0, webpack@^4.32.2: +webpack@^4.30.0: version "4.32.2" resolved "https://registry.yarnpkg.com/webpack/-/webpack-4.32.2.tgz#3639375364a617e84b914ddb2c770aed511e5bc8" integrity sha512-F+H2Aa1TprTQrpodRAWUMJn7A8MgDx82yQiNvYMaj3d1nv3HetKU0oqEulL9huj8enirKi8KvEXQ3QtuHF89Zg== @@ -9292,6 +9304,36 @@ webpack@^4.30.0, webpack@^4.32.2: watchpack "^1.5.0" webpack-sources "^1.3.0" +webpack@^4.33.0: + version "4.33.0" + resolved "https://registry.yarnpkg.com/webpack/-/webpack-4.33.0.tgz#c30fc4307db432e5c5e3333aaa7c16a15a3b277e" + integrity sha512-ggWMb0B2QUuYso6FPZKUohOgfm+Z0sVFs8WwWuSH1IAvkWs428VDNmOlAxvHGTB9Dm/qOB/qtE5cRx5y01clxw== + dependencies: + "@webassemblyjs/ast" "1.8.5" + "@webassemblyjs/helper-module-context" "1.8.5" + "@webassemblyjs/wasm-edit" "1.8.5" + "@webassemblyjs/wasm-parser" "1.8.5" + acorn "^6.0.5" + acorn-dynamic-import "^4.0.0" + ajv "^6.1.0" + ajv-keywords "^3.1.0" + chrome-trace-event "^1.0.0" + enhanced-resolve "^4.1.0" + eslint-scope "^4.0.0" + json-parse-better-errors "^1.0.2" + loader-runner "^2.3.0" + loader-utils "^1.1.0" + memory-fs "~0.4.1" + micromatch "^3.1.8" + mkdirp "~0.5.0" + neo-async "^2.5.0" + node-libs-browser "^2.0.0" + schema-utils "^1.0.0" + tapable "^1.1.0" + terser-webpack-plugin "^1.1.0" + watchpack "^1.5.0" + webpack-sources "^1.3.0" + webpackbar@^3.2.0: version "3.2.0" resolved "https://registry.yarnpkg.com/webpackbar/-/webpackbar-3.2.0.tgz#bdaad103fad11a4e612500e72aaae98b08ba493f"