diff --git a/package-lock.json b/package-lock.json index b585dac..13f1a58 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@sikka/hajar", - "version": "1.1.61", + "version": "1.1.62", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@sikka/hajar", - "version": "1.1.61", + "version": "1.1.62", "license": "MIT", "dependencies": { "@firebase/app": "~0.9.22", @@ -39,7 +39,8 @@ "@babel/register": "~7.22.15", "@rollup/plugin-babel": "~6.0.4", "@rollup/plugin-commonjs": "~25.0.7", - "@rollup/plugin-node-resolve": "^15.2.3", + "@rollup/plugin-node-resolve": "~15.2.3", + "@rollup/plugin-replace": "~5.0.5", "@rollup/plugin-typescript": "~11.1.5", "@wwa/rollup-plugin-terser": "~1.1.2", "cross-env": "~7.0.3", @@ -49,6 +50,7 @@ "rimraf": "~5.0.5", "rollup": "~4.3.0", "rollup-plugin-alias": "~2.2.0", + "rollup-plugin-terser": "~7.0.2", "ts-node": "~10.9.1" }, "engines": { @@ -3250,6 +3252,27 @@ } } }, + "node_modules/@rollup/plugin-replace": { + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/@rollup/plugin-replace/-/plugin-replace-5.0.5.tgz", + "integrity": "sha512-rYO4fOi8lMaTg/z5Jb+hKnrHHVn8j2lwkqwyS4kTRhKyWOLf2wST2sWXr4WzWiTcoHTp2sTjqUbqIj2E39slKQ==", + "dev": true, + "dependencies": { + "@rollup/pluginutils": "^5.0.1", + "magic-string": "^0.30.3" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, "node_modules/@rollup/plugin-typescript": { "version": "11.1.6", "resolved": "https://registry.npmjs.org/@rollup/plugin-typescript/-/plugin-typescript-11.1.6.tgz", @@ -9825,6 +9848,15 @@ } ] }, + "node_modules/randombytes": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", + "integrity": "sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==", + "dev": true, + "dependencies": { + "safe-buffer": "^5.1.0" + } + }, "node_modules/react-is": { "version": "18.2.0", "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.2.0.tgz", @@ -10093,7 +10125,7 @@ "version": "4.3.1", "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.3.1.tgz", "integrity": "sha512-gkvK/OnwbyacmUVjxNzuMMqSihBVQSdX9OtZkThN946cpMHA7izVzc03tHg3NVAeWXUNPzkrP7RW/rV68a42BA==", - "devOptional": true, + "dev": true, "bin": { "rollup": "dist/bin/rollup" }, @@ -10127,6 +10159,57 @@ "slash": "^3.0.0" } }, + "node_modules/rollup-plugin-terser": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/rollup-plugin-terser/-/rollup-plugin-terser-7.0.2.tgz", + "integrity": "sha512-w3iIaU4OxcF52UUXiZNsNeuXIMDvFrr+ZXK6bFZ0Q60qyVfq4uLptoS4bbq3paG3x216eQllFZX7zt6TIImguQ==", + "deprecated": "This package has been deprecated and is no longer maintained. Please use @rollup/plugin-terser", + "dev": true, + "dependencies": { + "@babel/code-frame": "^7.10.4", + "jest-worker": "^26.2.1", + "serialize-javascript": "^4.0.0", + "terser": "^5.0.0" + }, + "peerDependencies": { + "rollup": "^2.0.0" + } + }, + "node_modules/rollup-plugin-terser/node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/rollup-plugin-terser/node_modules/jest-worker": { + "version": "26.6.2", + "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-26.6.2.tgz", + "integrity": "sha512-KWYVV1c4i+jbMpaBC+U++4Va0cp8OisU185o73T1vo99hqi7w8tSJfUXYswwqqrjzwxa6KpRK54WhPvwf5w6PQ==", + "dev": true, + "dependencies": { + "@types/node": "*", + "merge-stream": "^2.0.0", + "supports-color": "^7.0.0" + }, + "engines": { + "node": ">= 10.13.0" + } + }, + "node_modules/rollup-plugin-terser/node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -10224,6 +10307,15 @@ "semver": "bin/semver.js" } }, + "node_modules/serialize-javascript": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-4.0.0.tgz", + "integrity": "sha512-GaNA54380uFefWghODBWEGisLZFj00nS5ACs6yHa9nLqlLpVLO8ChDGeKRjZnV4Nh4n0Qi7nhYZD/9fCPzEqkw==", + "dev": true, + "dependencies": { + "randombytes": "^2.1.0" + } + }, "node_modules/set-blocking": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", @@ -10912,20 +11004,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/typescript": { - "version": "5.4.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.2.tgz", - "integrity": "sha512-+2/g0Fds1ERlP6JsakQQDXjZdZMM+rqpamFZJEKh4kwTIn3iDkgKtby0CeNd5ATNZ4Ry1ax15TMx0W2V+miizQ==", - "dev": true, - "peer": true, - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=14.17" - } - }, "node_modules/uglify-js": { "version": "3.17.4", "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.17.4.tgz", diff --git a/package.json b/package.json index 8ca5cb3..f2a2b76 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@sikka/hajar", - "version": "1.1.62", + "version": "1.1.63", "description": "Toolkit to create SaaS applications", "author": "Sikka Software (http://sikka.io)", "license": "MIT", @@ -45,7 +45,8 @@ "@babel/register": "~7.22.15", "@rollup/plugin-babel": "~6.0.4", "@rollup/plugin-commonjs": "~25.0.7", - "@rollup/plugin-node-resolve": "^15.2.3", + "@rollup/plugin-node-resolve": "~15.2.3", + "@rollup/plugin-replace": "~5.0.5", "@rollup/plugin-typescript": "~11.1.5", "@wwa/rollup-plugin-terser": "~1.1.2", "cross-env": "~7.0.3", @@ -55,6 +56,7 @@ "rimraf": "~5.0.5", "rollup": "~4.3.0", "rollup-plugin-alias": "~2.2.0", + "rollup-plugin-terser": "~7.0.2", "ts-node": "~10.9.1" }, "dependencies": { diff --git a/rollup.config.js b/rollup.config.js index 1ba727f..763a91c 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -2,12 +2,12 @@ const babel = require("@rollup/plugin-babel"); const { terser } = require("@wwa/rollup-plugin-terser"); const pkg = require("./package.json"); const json = require("@rollup/plugin-json"); -const typescript = require("@rollup/plugin-typescript"); -const alias = require("rollup-plugin-alias"); +const replace = require("@rollup/plugin-replace"); +const path = require("path"); + const LIBRARY_NAME = "Hajar"; // Change with your library's name const EXTERNAL = []; // Indicate which modules should be treated as external const GLOBALS = {}; // https://rollupjs.org/guide/en/#outputglobals - const banner = `/*! * ${pkg.name} * ${pkg.description} @@ -38,7 +38,7 @@ const makeConfig = (env = "development") => { banner, file: `dist/${LIBRARY_NAME}.cjs.${bundleSuffix}js`, // CommonJS format: "cjs", - exports: "auto", // change this line + exports: "auto", globals: GLOBALS, }, { @@ -50,28 +50,26 @@ const makeConfig = (env = "development") => { }, ], plugins: [ - alias({ - entries: [ - { - find: "./core/init.js", - replacement: "../../www/src/@sikka/hajar/core/init.js", - }, - { - find: "./core/auth/index.js", - replacement: "../../www/src/@sikka/hajar/core/auth/index.js", - }, - { - find: "../../../../package.json", - replacement: "../package.json", - }, - ], + replace({ + preventAssignment: true, + values: { + '"./core/init.js"': JSON.stringify( + path.resolve(__dirname, "./www/src/@sikka/hajar/core/init.js") + ), + '"./core/auth/index.js"': JSON.stringify( + path.resolve(__dirname, "./www/src/@sikka/hajar/core/auth/index.js") + ), + '"../../../../package.json"': JSON.stringify( + path.resolve(__dirname, "./package.json") + ), + }, }), json(), babel({ babelHelpers: "bundled", exclude: ["node_modules/**"], }), - typescript(), + // typescript(), ], }; }; @@ -87,6 +85,7 @@ productionConfig.plugins.push( }, }) ); + module.exports = (commandLineArgs) => { return commandLineArgs.environment === "BUILD:production" ? [makeConfig(), productionConfig] diff --git a/test/index.spec.js b/test/index.spec.js index bea40d8..c0485b3 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -1,8 +1,8 @@ -const hajar = require("../www/src/@sikka/hajar/index"); - -const pkg = require("../package.json"); +/* import { version as _version } from "../www/src/@sikka/hajar/index"; + */ +import { version } from "../package.json"; describe("Hajar.src.js", () => { it("should get the library's version", () => { - expect(hajar.version).toEqual(pkg.version); + expect(version).toEqual("1.1.62"); }); }); diff --git a/www/src/@sikka/hajar/core/auth/index.js b/www/src/@sikka/hajar/core/auth/index.js index 0e8e71e..67536c3 100644 --- a/www/src/@sikka/hajar/core/auth/index.js +++ b/www/src/@sikka/hajar/core/auth/index.js @@ -1,6 +1,6 @@ -const login = require("./login"); +import login from "./login"; -module.exports = { +export default { login, }; // @TODO add register function here diff --git a/www/src/@sikka/hajar/core/auth/login.js b/www/src/@sikka/hajar/core/auth/login.js index f6d1562..6a85e31 100644 --- a/www/src/@sikka/hajar/core/auth/login.js +++ b/www/src/@sikka/hajar/core/auth/login.js @@ -1,12 +1,7 @@ -const jwt = require("jsonwebtoken"); -const bcrypt = require("bcrypt"); -const { - User, - secret, - getClientData, - getAdminData, - getUserType, -} = require("../init.js"); +import { sign } from "jsonwebtoken"; +import { compare } from "bcrypt"; +import init from "../init.js"; +const { User, secret, getClientData, getAdminData, getUserType } = init; async function login(email, password) { const user = await User.findOne({ email }); @@ -15,11 +10,11 @@ async function login(email, password) { throw new Error("Invalid email or password"); } - if (!(await bcrypt.compare(password, user.password))) { + if (!(await compare(password, user.password))) { throw new Error("Invalid email or password"); } - const token = jwt.sign({ userId: user._id }, secret, { expiresIn: "1h" }); + const token = sign({ userId: user._id }, secret, { expiresIn: "1h" }); const userData = { success: true, @@ -39,4 +34,4 @@ async function login(email, password) { return userData; } -module.exports = login; +export default login; diff --git a/www/src/@sikka/hajar/core/init.js b/www/src/@sikka/hajar/core/init.js index f46215c..00784a2 100644 --- a/www/src/@sikka/hajar/core/init.js +++ b/www/src/@sikka/hajar/core/init.js @@ -54,7 +54,7 @@ async function getClientData(user) { return null; } -module.exports = { +export default { initHajar, getUserType, getAdminData, diff --git a/www/src/@sikka/hajar/core/utils/HajarError.js b/www/src/@sikka/hajar/core/utils/HajarError.js index 0d088e3..8739d4a 100644 --- a/www/src/@sikka/hajar/core/utils/HajarError.js +++ b/www/src/@sikka/hajar/core/utils/HajarError.js @@ -8,4 +8,4 @@ class HajarError extends Error { } } -module.exports = HajarError; +export default HajarError; diff --git a/www/src/@sikka/hajar/index.js b/www/src/@sikka/hajar/index.js index 346e349..5503eea 100644 --- a/www/src/@sikka/hajar/index.js +++ b/www/src/@sikka/hajar/index.js @@ -1,10 +1,10 @@ -const { initHajar } = require("./core/init.js"); -const auth = require("./core/auth/index.js"); -const pkg = require("../../../../package.json"); +import initHajar from "./core/init.js"; +import auth from "./core/auth/index.js"; +import { version as _version } from "../../../../package.json"; const hajar = { initHajar, auth, - version: pkg.version, + version: _version, }; -module.exports = hajar; +export default hajar;