diff --git a/package-lock.json b/package-lock.json index f1a3e5d..08b09f6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1361,11 +1361,13 @@ "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, "node_modules/axios": { - "version": "0.21.4", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz", - "integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==", + "version": "1.7.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.2.tgz", + "integrity": "sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw==", "dependencies": { - "follow-redirects": "^1.14.0" + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" } }, "node_modules/axios-mock-adapter": { @@ -2090,9 +2092,9 @@ } }, "node_modules/follow-redirects": { - "version": "1.15.3", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz", - "integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==", + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", "funding": [ { "type": "individual", @@ -3725,6 +3727,11 @@ "node": ">= 6" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "node_modules/psl": { "version": "1.9.0", "resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz", @@ -4496,11 +4503,11 @@ "name": "@dative-gpi/bones-ui", "version": "1.0.0", "license": "ISC", - "dependencies": { + "peerDependencies": { "@types/lodash": "^4.14.197", "ajv": "^8.11.0", "ajv-dist": "^8.11.0", - "axios": "^0.21.1", + "axios": "^1.7.2", "lodash": "^4.17.21", "vue": "^3.2.0" } @@ -4512,10 +4519,17 @@ "jest-environment-jsdom": "^29.7.0" }, "devDependencies": { + "@dative-gpi/bones-ui": "1.0.0", "@types/jest": "^29.5.5", + "@types/lodash": "^4.14.197", + "ajv": "^8.11.0", + "ajv-dist": "^8.11.0", + "axios": "^1.7.2", "jest": "^29.7.0", + "lodash": "^4.17.21", "ts-jest": "^29.1.1", - "typescript": "^5.2.2" + "typescript": "^5.2.2", + "vue": "^3.2.0" } } } diff --git a/src/Bones.UI/index.ts b/src/Bones.UI/index.ts index a64ffcc..b3be3fb 100644 --- a/src/Bones.UI/index.ts +++ b/src/Bones.UI/index.ts @@ -1,5 +1,4 @@ import "./shims-plugin.d.ts" -import "./shims-axios.d.ts" export * from "./abstractions" export * from "./composables" diff --git a/src/Bones.UI/package.json b/src/Bones.UI/package.json index 3a53f9c..e01276e 100644 --- a/src/Bones.UI/package.json +++ b/src/Bones.UI/package.json @@ -6,11 +6,11 @@ "author": "", "license": "ISC", "sideEffects": false, - "dependencies": { + "peerDependencies": { "@types/lodash": "^4.14.197", "ajv": "^8.11.0", "ajv-dist": "^8.11.0", - "axios": "^0.21.1", + "axios": "^1.7.2", "vue": "^3.2.0", "lodash": "^4.17.21" } diff --git a/src/Bones.UI/shims-axios.d.ts b/src/Bones.UI/shims-axios.d.ts deleted file mode 100644 index a0b4d29..0000000 --- a/src/Bones.UI/shims-axios.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -declare module 'axios/lib/helpers/buildURL' { - function buildURL(url: string, params?: any, paramsSerialized?: any): string; - export = buildURL; -} \ No newline at end of file diff --git a/src/Bones.UI/tools/buildURL.ts b/src/Bones.UI/tools/buildURL.ts new file mode 100644 index 0000000..461508f --- /dev/null +++ b/src/Bones.UI/tools/buildURL.ts @@ -0,0 +1,111 @@ +function encode(val: string) { + return encodeURIComponent(val). + replace(/%3A/gi, ':'). + replace(/%24/g, '$'). + replace(/%2C/gi, ','). + replace(/%20/g, '+'). + replace(/%5B/gi, '['). + replace(/%5D/gi, ']'); +} + +var toString = Object.prototype.toString; + +function forEach(obj: any, fn: any) { + // Don't bother if no value provided + if (obj === null || typeof obj === 'undefined') { + return; + } + + // Force an array if not already something iterable + if (typeof obj !== 'object') { + /*eslint no-param-reassign:0*/ + obj = [obj]; + } + + if (isArray(obj)) { + // Iterate over array values + for (var i = 0, l = obj.length; i < l; i++) { + fn.call(null, obj[i], i, obj); + } + } else { + // Iterate over object keys + for (var key in obj) { + if (Object.prototype.hasOwnProperty.call(obj, key)) { + fn.call(null, obj[key], key, obj); + } + } + } +} + +function isURLSearchParams(val: any) { + return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams; +} + +function isArray(val: any) { + return toString.call(val) === '[object Array]'; +} + +function isDate(val: any) { + return toString.call(val) === '[object Date]'; +} + +function isObject(val: any) { + return val !== null && typeof val === 'object'; +} + +/** + * Build a URL by appending params to the end + * + * @param {string} url The base of the url (e.g., http://www.google.com) + * @param {object} [params] The params to be appended + * @returns {string} The formatted url + */ +export function buildURL(url: string, params?: any, paramsSerializer?: any) { + /*eslint no-param-reassign:0*/ + if (!params) { + return url; + } + + var serializedParams; + if (paramsSerializer) { + serializedParams = paramsSerializer(params); + } else if (isURLSearchParams(params)) { + serializedParams = params.toString(); + } else { + var parts : string[] = []; + + forEach(params, function serialize(val: any, key: any) { + if (val === null || typeof val === 'undefined') { + return; + } + + if (isArray(val)) { + key = key + '[]'; + } else { + val = [val]; + } + + forEach(val, function parseValue(v: any) { + if (isDate(v)) { + v = v.toISOString(); + } else if (isObject(v)) { + v = JSON.stringify(v); + } + parts.push(encode(key) + '=' + encode(v)); + }); + }); + + serializedParams = parts.join('&'); + } + + if (serializedParams) { + var hashmarkIndex = url.indexOf('#'); + if (hashmarkIndex !== -1) { + url = url.slice(0, hashmarkIndex); + } + + url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams; + } + + return url; +}; diff --git a/src/Bones.UI/tools/urlTools.ts b/src/Bones.UI/tools/urlTools.ts index 02b64a2..29ed0b6 100644 --- a/src/Bones.UI/tools/urlTools.ts +++ b/src/Bones.UI/tools/urlTools.ts @@ -1,5 +1,5 @@ import _ from "lodash"; -import axiosBuildURL from 'axios/lib/helpers/buildURL'; +import { buildURL as axiosBuildURL } from "./buildURL"; function deepFlat(key: string, value: any): { key: string, value: any }[] { if ((typeof value !== 'object' || value === null || value instanceof Date)) { diff --git a/src/Bones.UI/tools/utils.ts b/src/Bones.UI/tools/utils.ts new file mode 100644 index 0000000..e69de29 diff --git a/tests/Bones.UI.Tests/package.json b/tests/Bones.UI.Tests/package.json index f617deb..9d751ef 100644 --- a/tests/Bones.UI.Tests/package.json +++ b/tests/Bones.UI.Tests/package.json @@ -1,10 +1,17 @@ { "name": "bones-ui-tests", "devDependencies": { + "@dative-gpi/bones-ui": "1.0.0", "@types/jest": "^29.5.5", "jest": "^29.7.0", "ts-jest": "^29.1.1", - "typescript": "^5.2.2" + "typescript": "^5.2.2", + "@types/lodash": "^4.14.197", + "ajv": "^8.11.0", + "ajv-dist": "^8.11.0", + "axios": "^1.7.2", + "vue": "^3.2.0", + "lodash": "^4.17.21" }, "scripts": { "test": "jest" diff --git a/tests/Bones.UI.Tests/tests/composable.test.ts b/tests/Bones.UI.Tests/tests/composable.test.ts index b80038b..ad9a0a2 100644 --- a/tests/Bones.UI.Tests/tests/composable.test.ts +++ b/tests/Bones.UI.Tests/tests/composable.test.ts @@ -1,11 +1,13 @@ /** * @jest-environment jsdom */ + import * as all from '@dative-gpi/bones-ui'; import { ServiceFactory } from '@dative-gpi/bones-ui'; import { useTestUser, useTestUsers, TEST_USERS_URL, TEST_USER_URL, useCreateTestUser, useUpdateTestUser, useRemoveTestUser } from '../services/testUserService'; import MockAdapter from 'axios-mock-adapter'; -import buildURL from 'axios/lib/helpers/buildURL'; + +import { buildURL } from '@dative-gpi/bones-ui/tools/buildURL'; const mock = new MockAdapter(ServiceFactory.http); diff --git a/tests/Bones.UI.Tests/tsconfig.json b/tests/Bones.UI.Tests/tsconfig.json index 87da125..bc28694 100644 --- a/tests/Bones.UI.Tests/tsconfig.json +++ b/tests/Bones.UI.Tests/tsconfig.json @@ -1,16 +1,17 @@ { "compilerOptions": { "baseUrl": ".", - "target": "ESNext", + "target": "ES6", "useDefineForClassFields": true, - "module": "ESNext", + "module": "ES6", "moduleResolution": "Node", "strict": true, "jsx": "preserve", "resolveJsonModule": true, "isolatedModules": true, "esModuleInterop": true, - "lib": ["ESNext", "DOM"], + "allowSyntheticDefaultImports": true, + "lib": ["ES6", "DOM"], "skipLibCheck": true, "noEmit": true, "paths": {