3a-ecommerce-utils 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/dist/{chunk-PEAZVBSD.mjs → chunk-E26IEY7N.mjs} +0 -10
- package/dist/chunk-NOOKRTMI.mjs +1603 -0
- package/dist/client-BHgqHSo9.d.ts +464 -0
- package/dist/client-DgNiKrLe.d.mts +464 -0
- package/dist/client.d.mts +3 -0
- package/dist/client.d.ts +3 -0
- package/dist/client.js +2338 -0
- package/dist/client.mjs +344 -0
- package/dist/config/tailwind.config.js +188 -0
- package/dist/config/tailwind.config.mjs +155 -0
- package/dist/config/vite.config.js +114 -0
- package/dist/config/vite.config.mjs +78 -0
- package/dist/config/vitest.base.config.js +98 -0
- package/dist/config/vitest.base.config.mjs +61 -0
- package/dist/config/webpack.base.config.js +148 -0
- package/dist/config/webpack.base.config.mjs +110 -0
- package/dist/index.d.mts +3 -462
- package/dist/index.d.ts +3 -462
- package/dist/index.js +8 -16
- package/dist/index.mjs +177 -1526
- package/dist/validation/server.d.mts +1 -1
- package/dist/validation/server.d.ts +1 -1
- package/dist/validation/server.js +14 -24
- package/dist/validation/server.mjs +2 -2
- package/package.json +28 -3
- package/src/api/errorHandler.ts +1 -1
- package/src/api/logger.client.ts +1 -1
- package/src/api/logger.ts +1 -1
- package/src/client.ts +41 -0
- package/src/config/jest.backend.config.js +3 -8
- package/src/config/jest.frontend.config.js +3 -3
- package/src/config/tsconfig.base.json +6 -6
- package/src/config/vite.config.ts +3 -3
- package/src/config/vitest.base.config.ts +3 -3
- package/src/queries.ts +28 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Request, Response, NextFunction } from 'express';
|
|
2
2
|
export { y as batchValidate, h as isValidCouponCode, i as isValidEmail, p as isValidObjectId, a as isValidPassword, d as isValidPhone, f as isValidPostalCode, t as isValidSku, r as isValidUrl, j as validateCouponCode, w as validateDate, x as validateDateRange, n as validateDiscountPercentage, v as validateEmail, c as validateName, q as validateObjectId, o as validatePagination, b as validatePassword, e as validatePhone, g as validatePostalCode, k as validatePrice, l as validateQuantity, m as validateRating, u as validateSku, s as validateUrl } from '../client-DYGi_pyp.mjs';
|
|
3
|
-
import { LogLevel } from '
|
|
3
|
+
import { LogLevel } from '3a-ecommerce-types';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Server-side Logger with file system support
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Request, Response, NextFunction } from 'express';
|
|
2
2
|
export { y as batchValidate, h as isValidCouponCode, i as isValidEmail, p as isValidObjectId, a as isValidPassword, d as isValidPhone, f as isValidPostalCode, t as isValidSku, r as isValidUrl, j as validateCouponCode, w as validateDate, x as validateDateRange, n as validateDiscountPercentage, v as validateEmail, c as validateName, q as validateObjectId, o as validatePagination, b as validatePassword, e as validatePhone, g as validatePostalCode, k as validatePrice, l as validateQuantity, m as validateRating, u as validateSku, s as validateUrl } from '../client-DYGi_pyp.js';
|
|
3
|
-
import { LogLevel } from '
|
|
3
|
+
import { LogLevel } from '3a-ecommerce-types';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Server-side Logger with file system support
|
|
@@ -371,22 +371,12 @@ var batchValidate = (validations) => {
|
|
|
371
371
|
// src/api/logger.ts
|
|
372
372
|
var import_fs = __toESM(require("fs"));
|
|
373
373
|
var import_path = __toESM(require("path"));
|
|
374
|
-
|
|
375
|
-
// ../types/dist/index.mjs
|
|
376
|
-
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
377
|
-
LogLevel2["DEBUG"] = "DEBUG";
|
|
378
|
-
LogLevel2["INFO"] = "INFO";
|
|
379
|
-
LogLevel2["WARN"] = "WARN";
|
|
380
|
-
LogLevel2["ERROR"] = "ERROR";
|
|
381
|
-
return LogLevel2;
|
|
382
|
-
})(LogLevel || {});
|
|
383
|
-
|
|
384
|
-
// src/api/logger.ts
|
|
374
|
+
var import_a_ecommerce_types = require("3a-ecommerce-types");
|
|
385
375
|
var LOG_LEVEL_PRIORITY = {
|
|
386
|
-
[LogLevel.DEBUG]: 0,
|
|
387
|
-
[LogLevel.INFO]: 1,
|
|
388
|
-
[LogLevel.WARN]: 2,
|
|
389
|
-
[LogLevel.ERROR]: 3
|
|
376
|
+
[import_a_ecommerce_types.LogLevel.DEBUG]: 0,
|
|
377
|
+
[import_a_ecommerce_types.LogLevel.INFO]: 1,
|
|
378
|
+
[import_a_ecommerce_types.LogLevel.WARN]: 2,
|
|
379
|
+
[import_a_ecommerce_types.LogLevel.ERROR]: 3
|
|
390
380
|
};
|
|
391
381
|
var Logger = class {
|
|
392
382
|
static configure(options) {
|
|
@@ -396,7 +386,7 @@ var Logger = class {
|
|
|
396
386
|
if (options.logFilePath) this.logFilePath = options.logFilePath;
|
|
397
387
|
if (options.logLevel) {
|
|
398
388
|
const level = typeof options.logLevel === "string" ? options.logLevel.toUpperCase() : options.logLevel;
|
|
399
|
-
if (Object.values(LogLevel).includes(level)) {
|
|
389
|
+
if (Object.values(import_a_ecommerce_types.LogLevel).includes(level)) {
|
|
400
390
|
this.logLevel = level;
|
|
401
391
|
}
|
|
402
392
|
}
|
|
@@ -416,16 +406,16 @@ var Logger = class {
|
|
|
416
406
|
return `[${entry.timestamp}] [${entry.level}]${entry.context ? ` [${entry.context}]` : ""}: ${entry.message}`;
|
|
417
407
|
}
|
|
418
408
|
static debug(message, data, context) {
|
|
419
|
-
this.log(LogLevel.DEBUG, message, data, context);
|
|
409
|
+
this.log(import_a_ecommerce_types.LogLevel.DEBUG, message, data, context);
|
|
420
410
|
}
|
|
421
411
|
static info(message, data, context) {
|
|
422
|
-
this.log(LogLevel.INFO, message, data, context);
|
|
412
|
+
this.log(import_a_ecommerce_types.LogLevel.INFO, message, data, context);
|
|
423
413
|
}
|
|
424
414
|
static warn(message, data, context) {
|
|
425
|
-
this.log(LogLevel.WARN, message, data, context);
|
|
415
|
+
this.log(import_a_ecommerce_types.LogLevel.WARN, message, data, context);
|
|
426
416
|
}
|
|
427
417
|
static error(message, error, context) {
|
|
428
|
-
this.log(LogLevel.ERROR, message, error, context);
|
|
418
|
+
this.log(import_a_ecommerce_types.LogLevel.ERROR, message, error, context);
|
|
429
419
|
}
|
|
430
420
|
static log(level, message, data, context) {
|
|
431
421
|
if (!this.shouldLog(level)) return;
|
|
@@ -440,13 +430,13 @@ var Logger = class {
|
|
|
440
430
|
if (!this.enableConsole) return;
|
|
441
431
|
const formatted = this.format(entry);
|
|
442
432
|
switch (level) {
|
|
443
|
-
case LogLevel.ERROR:
|
|
433
|
+
case import_a_ecommerce_types.LogLevel.ERROR:
|
|
444
434
|
console.error(formatted, data ?? "");
|
|
445
435
|
break;
|
|
446
|
-
case LogLevel.WARN:
|
|
436
|
+
case import_a_ecommerce_types.LogLevel.WARN:
|
|
447
437
|
console.warn(formatted, data ?? "");
|
|
448
438
|
break;
|
|
449
|
-
case LogLevel.INFO:
|
|
439
|
+
case import_a_ecommerce_types.LogLevel.INFO:
|
|
450
440
|
console.info(formatted, data ?? "");
|
|
451
441
|
break;
|
|
452
442
|
default:
|
|
@@ -468,7 +458,7 @@ Logger.maxLogs = 1e3;
|
|
|
468
458
|
Logger.enableConsole = true;
|
|
469
459
|
Logger.enableFile = false;
|
|
470
460
|
Logger.logFilePath = import_path.default.join(process.cwd(), "logs/app.log");
|
|
471
|
-
Logger.logLevel = LogLevel.DEBUG;
|
|
461
|
+
Logger.logLevel = import_a_ecommerce_types.LogLevel.DEBUG;
|
|
472
462
|
|
|
473
463
|
// src/validation/server.ts
|
|
474
464
|
var validate = (req, res, next) => {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
LogLevel,
|
|
3
2
|
batchValidate,
|
|
4
3
|
isValidCouponCode,
|
|
5
4
|
isValidEmail,
|
|
@@ -25,7 +24,7 @@ import {
|
|
|
25
24
|
validateRating,
|
|
26
25
|
validateSku,
|
|
27
26
|
validateUrl
|
|
28
|
-
} from "../chunk-
|
|
27
|
+
} from "../chunk-E26IEY7N.mjs";
|
|
29
28
|
|
|
30
29
|
// src/validation/server.ts
|
|
31
30
|
import { validationResult } from "express-validator";
|
|
@@ -33,6 +32,7 @@ import { validationResult } from "express-validator";
|
|
|
33
32
|
// src/api/logger.ts
|
|
34
33
|
import fs from "fs";
|
|
35
34
|
import path from "path";
|
|
35
|
+
import { LogLevel } from "3a-ecommerce-types";
|
|
36
36
|
var LOG_LEVEL_PRIORITY = {
|
|
37
37
|
[LogLevel.DEBUG]: 0,
|
|
38
38
|
[LogLevel.INFO]: 1,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "3a-ecommerce-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Utility functions for 3A Softwares E-Commerce",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -11,18 +11,43 @@
|
|
|
11
11
|
"import": "./dist/index.mjs",
|
|
12
12
|
"require": "./dist/index.js"
|
|
13
13
|
},
|
|
14
|
+
"./client": {
|
|
15
|
+
"types": "./dist/client.d.ts",
|
|
16
|
+
"import": "./dist/client.mjs",
|
|
17
|
+
"require": "./dist/client.js"
|
|
18
|
+
},
|
|
14
19
|
"./server": {
|
|
15
20
|
"types": "./dist/validation/server.d.ts",
|
|
16
21
|
"import": "./dist/validation/server.mjs",
|
|
17
22
|
"require": "./dist/validation/server.js"
|
|
18
|
-
}
|
|
23
|
+
},
|
|
24
|
+
"./config/jest.backend": "./src/config/jest.backend.config.js",
|
|
25
|
+
"./config/jest.frontend": "./src/config/jest.frontend.config.js",
|
|
26
|
+
"./config/postcss": "./src/config/postcss.config.js",
|
|
27
|
+
"./config/tailwind": {
|
|
28
|
+
"import": "./dist/config/tailwind.config.mjs",
|
|
29
|
+
"require": "./dist/config/tailwind.config.js"
|
|
30
|
+
},
|
|
31
|
+
"./config/vite": {
|
|
32
|
+
"import": "./dist/config/vite.config.mjs",
|
|
33
|
+
"require": "./dist/config/vite.config.js"
|
|
34
|
+
},
|
|
35
|
+
"./config/vitest": {
|
|
36
|
+
"import": "./dist/config/vitest.base.config.mjs",
|
|
37
|
+
"require": "./dist/config/vitest.base.config.js"
|
|
38
|
+
},
|
|
39
|
+
"./config/webpack": {
|
|
40
|
+
"import": "./dist/config/webpack.base.config.mjs",
|
|
41
|
+
"require": "./dist/config/webpack.base.config.js"
|
|
42
|
+
},
|
|
43
|
+
"./config/tsconfig.base.json": "./src/config/tsconfig.base.json"
|
|
19
44
|
},
|
|
20
45
|
"files": [
|
|
21
46
|
"dist",
|
|
22
47
|
"src"
|
|
23
48
|
],
|
|
24
49
|
"scripts": {
|
|
25
|
-
"build": "tsup src/index.ts src/validation/server.ts --format cjs,esm --dts --clean --external 3a-ecommerce-types",
|
|
50
|
+
"build": "tsup src/index.ts src/client.ts src/validation/server.ts --format cjs,esm --dts --clean --external 3a-ecommerce-types && tsup src/config/tailwind.config.ts src/config/vite.config.ts src/config/vitest.base.config.ts src/config/webpack.base.config.ts --format cjs,esm --no-dts --outDir dist/config --external 3a-ecommerce-types --external vite --external vitest --external webpack --external daisyui --external @vitejs/plugin-react --external html-webpack-plugin --external mini-css-extract-plugin --external webpack-dev-server --external @storybook/addon-vitest --external @vitest/browser-playwright",
|
|
26
51
|
"prepublishOnly": "npm run build",
|
|
27
52
|
"test": "vitest",
|
|
28
53
|
"test:coverage": "vitest run --coverage"
|
package/src/api/errorHandler.ts
CHANGED
package/src/api/logger.client.ts
CHANGED
package/src/api/logger.ts
CHANGED
package/src/client.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-safe utilities for browser environments
|
|
3
|
+
* This entry point excludes server-side dependencies like axios/http2
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export {
|
|
7
|
+
storeAuth,
|
|
8
|
+
getStoredAuth,
|
|
9
|
+
isTokenExpired,
|
|
10
|
+
willTokenExpireSoon,
|
|
11
|
+
clearAuth,
|
|
12
|
+
validateUserRole,
|
|
13
|
+
getCurrentUser,
|
|
14
|
+
getAccessToken,
|
|
15
|
+
getRefreshToken,
|
|
16
|
+
updateAccessToken,
|
|
17
|
+
setupAutoRefresh,
|
|
18
|
+
type AuthTokens,
|
|
19
|
+
type StoredAuth,
|
|
20
|
+
} from './auth';
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
setCookie,
|
|
24
|
+
getCookie,
|
|
25
|
+
removeCookie,
|
|
26
|
+
areCookiesEnabled,
|
|
27
|
+
AUTH_COOKIE_NAMES,
|
|
28
|
+
} from './cookies';
|
|
29
|
+
|
|
30
|
+
// Export only client-safe helpers
|
|
31
|
+
export * from './helpers';
|
|
32
|
+
export * from './constants';
|
|
33
|
+
|
|
34
|
+
// Export client-safe validation (not server validation)
|
|
35
|
+
export * from './validation/client';
|
|
36
|
+
|
|
37
|
+
// Export client-safe logger
|
|
38
|
+
export { Logger } from './api/logger.client';
|
|
39
|
+
|
|
40
|
+
// Export GraphQL query strings (browser-safe, no http dependencies)
|
|
41
|
+
export * from './queries';
|
|
@@ -16,12 +16,7 @@ module.exports = {
|
|
|
16
16
|
],
|
|
17
17
|
},
|
|
18
18
|
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
|
|
19
|
-
collectCoverageFrom: [
|
|
20
|
-
'src/**/*.ts',
|
|
21
|
-
'!src/**/*.d.ts',
|
|
22
|
-
'!src/swagger/**',
|
|
23
|
-
'!src/index.ts',
|
|
24
|
-
],
|
|
19
|
+
collectCoverageFrom: ['src/**/*.ts', '!src/**/*.d.ts', '!src/swagger/**', '!src/index.ts'],
|
|
25
20
|
coverageDirectory: 'coverage',
|
|
26
21
|
coverageReporters: ['text', 'lcov', 'html'],
|
|
27
22
|
coverageThreshold: {
|
|
@@ -36,7 +31,7 @@ module.exports = {
|
|
|
36
31
|
testTimeout: 10000,
|
|
37
32
|
verbose: true,
|
|
38
33
|
moduleNameMapper: {
|
|
39
|
-
'
|
|
40
|
-
'
|
|
34
|
+
'^3a-ecommerce-utils/server$': '<rootDir>/tests/__mocks__/utils.ts',
|
|
35
|
+
'^3a-ecommerce-types$': '<rootDir>/../../packages/types/src/index.ts',
|
|
41
36
|
},
|
|
42
37
|
};
|
|
@@ -11,9 +11,9 @@ module.exports = {
|
|
|
11
11
|
// Handle CSS imports
|
|
12
12
|
'\\.(css|less|scss|sass)$': 'identity-obj-proxy',
|
|
13
13
|
// Handle @e-commerce packages - projects should override these
|
|
14
|
-
'
|
|
15
|
-
'
|
|
16
|
-
'
|
|
14
|
+
'^3a-ecommerce-utils$': '<rootDir>/tests/__mocks__/utils.ts',
|
|
15
|
+
'^3a-ecommerce-ui-library$': '<rootDir>/tests/__mocks__/ui-library.tsx',
|
|
16
|
+
'^3a-ecommerce-types$': '<rootDir>/tests/__mocks__/types.ts',
|
|
17
17
|
// Handle FontAwesome
|
|
18
18
|
'^@fortawesome/react-fontawesome$': '<rootDir>/tests/__mocks__/fontawesome.tsx',
|
|
19
19
|
},
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
"baseUrl": ".",
|
|
26
26
|
"types": ["vite/client"],
|
|
27
27
|
"paths": {
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
28
|
+
"3a-ecommerce-types": ["../../packages/types/src"],
|
|
29
|
+
"3a-ecommerce-types/*": ["../../packages/types/src/*"],
|
|
30
|
+
"3a-ecommerce-ui-library": ["../../packages/ui-library/src"],
|
|
31
|
+
"3a-ecommerce-ui-library/*": ["../../packages/ui-library/src/*"],
|
|
32
|
+
"3a-ecommerce-utils": ["../../packages/utils/src"],
|
|
33
|
+
"3a-ecommerce-utils/*": ["../../packages/utils/src/*"]
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -10,9 +10,9 @@ export function createBaseViteConfig(rootDir: string): UserConfig {
|
|
|
10
10
|
},
|
|
11
11
|
resolve: {
|
|
12
12
|
alias: {
|
|
13
|
-
'
|
|
14
|
-
'
|
|
15
|
-
'
|
|
13
|
+
'3a-ecommerce-ui-library': path.resolve(rootDir, '../../packages/ui-library/src'),
|
|
14
|
+
'3a-ecommerce-types': path.resolve(rootDir, '../../packages/types/src'),
|
|
15
|
+
'3a-ecommerce-utils': path.resolve(rootDir, '../../packages/utils/src'),
|
|
16
16
|
},
|
|
17
17
|
},
|
|
18
18
|
});
|
|
@@ -40,9 +40,9 @@ export function createBrowserVitestConfig(rootDir: string, options?: {
|
|
|
40
40
|
resolve: {
|
|
41
41
|
alias: {
|
|
42
42
|
'@': path.resolve(rootDir, './src'),
|
|
43
|
-
'
|
|
44
|
-
'
|
|
45
|
-
'
|
|
43
|
+
'3a-ecommerce-ui-library': path.resolve(rootDir, '../../packages/ui-library/src'),
|
|
44
|
+
'3a-ecommerce-utils': path.resolve(rootDir, '../../packages/utils/src'),
|
|
45
|
+
'3a-ecommerce-types': path.resolve(rootDir, '../../packages/types/src'),
|
|
46
46
|
},
|
|
47
47
|
},
|
|
48
48
|
});
|
package/src/queries.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GraphQL Query Strings Export (browser-safe)
|
|
3
|
+
* These are just string constants - no http/axios dependencies
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// User queries
|
|
7
|
+
export * from './api/user.queries';
|
|
8
|
+
|
|
9
|
+
// Product queries
|
|
10
|
+
export * from './api/product.queries';
|
|
11
|
+
|
|
12
|
+
// Order queries
|
|
13
|
+
export * from './api/order.queries';
|
|
14
|
+
|
|
15
|
+
// Coupon queries
|
|
16
|
+
export * from './api/coupon.queries';
|
|
17
|
+
|
|
18
|
+
// Category queries
|
|
19
|
+
export * from './api/category.queries';
|
|
20
|
+
|
|
21
|
+
// Dashboard queries
|
|
22
|
+
export * from './api/dashboard.queries';
|
|
23
|
+
|
|
24
|
+
// Review queries
|
|
25
|
+
export * from './api/review.queries';
|
|
26
|
+
|
|
27
|
+
// Address queries
|
|
28
|
+
export * from './api/address.queries';
|