@fixefy/fixefy-ui-utils 0.0.2 → 0.0.4

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.
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCurrency = exports.setCurrency = exports.flushAll = exports.flushWorkspace = exports.setWorkspace = exports.getWorkspace = exports.flushLastActivity = exports.setLastActivity = exports.getLastActivity = exports.setHeaders = exports.getHeaders = exports.defaultHeaders = void 0;
4
+ const nookies_1 = require("nookies");
5
+ exports.defaultHeaders = {
6
+ 'bundle-name': '',
7
+ cur: {
8
+ _id: '5e8c8dfdfca1360007d7b654',
9
+ value: '5e8c8dfdfca1360007d7b654',
10
+ code: 'usd',
11
+ namePlural: 'us dollars',
12
+ symbol: '$',
13
+ },
14
+ hl: 'en',
15
+ 'is-explain': true,
16
+ 'last-activity': 0,
17
+ };
18
+ const getHeaders = (ctx, options = {}) => {
19
+ let _headers = (0, nookies_1.parseCookies)(ctx)['fixefy:headers'];
20
+ _headers = _headers && typeof _headers === 'string' ? JSON.parse(_headers) : typeof _headers === 'object' ? _headers : {};
21
+ const headers = Object.assign(Object.assign({}, exports.defaultHeaders), { ws: (0, exports.getWorkspace)(ctx), cur: (0, exports.getCurrency)(ctx)._id, 'last-activity': (0, exports.getLastActivity)(ctx) });
22
+ return headers;
23
+ };
24
+ exports.getHeaders = getHeaders;
25
+ const setHeaders = (ctx, _headers) => {
26
+ typeof _headers === 'string' ? (0, nookies_1.setCookie)(ctx, 'fixefy:headers', Object.assign({}, JSON.parse(_headers)), { maxAge: 7 * 24 * 60 * 60, path: '/' }) : (0, nookies_1.setCookie)(ctx, 'fixefy:headers', Object.assign({}, _headers), { maxAge: 7 * 24 * 60 * 60, path: '/' });
27
+ };
28
+ exports.setHeaders = setHeaders;
29
+ const getLastActivity = (ctx) => { };
30
+ exports.getLastActivity = getLastActivity;
31
+ const setLastActivity = (ctx) => { };
32
+ exports.setLastActivity = setLastActivity;
33
+ const flushLastActivity = (ctx) => { };
34
+ exports.flushLastActivity = flushLastActivity;
35
+ const getWorkspace = (ctx) => {
36
+ var _a;
37
+ const rv = (_a = (0, nookies_1.parseCookies)(ctx)['ws']) !== null && _a !== void 0 ? _a : exports.defaultHeaders['ws'];
38
+ return rv;
39
+ };
40
+ exports.getWorkspace = getWorkspace;
41
+ const setWorkspace = (ctx, ws) => {
42
+ (0, nookies_1.setCookie)(ctx, 'ws', ws, { maxAge: 7 * 24 * 60 * 60, path: '/' });
43
+ };
44
+ exports.setWorkspace = setWorkspace;
45
+ const flushWorkspace = (ctx) => {
46
+ (0, nookies_1.destroyCookie)(ctx, 'ws', { path: '/' });
47
+ };
48
+ exports.flushWorkspace = flushWorkspace;
49
+ const flushAll = (ctx) => {
50
+ (0, exports.flushLastActivity)(ctx);
51
+ (0, exports.flushWorkspace)(ctx);
52
+ };
53
+ exports.flushAll = flushAll;
54
+ const setCurrency = (ctx, currency) => {
55
+ (0, nookies_1.setCookie)(ctx, 'cur', JSON.stringify(currency), { maxAge: 7 * 24 * 60 * 60, path: '/' });
56
+ };
57
+ exports.setCurrency = setCurrency;
58
+ const getCurrency = (ctx) => {
59
+ var _a;
60
+ const cur = (_a = (0, nookies_1.parseCookies)(ctx)['cur']) !== null && _a !== void 0 ? _a : exports.defaultHeaders['cur'];
61
+ if (cur) {
62
+ if (cur === 'usd' || cur === 'eur') {
63
+ (0, exports.setCurrency)(ctx, exports.defaultHeaders['cur']);
64
+ }
65
+ return typeof cur === 'string' ? JSON.parse(cur) : cur;
66
+ }
67
+ };
68
+ exports.getCurrency = getCurrency;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.imageLoader = void 0;
4
+ const imageLoader = ({ src, root }) => {
5
+ const transformedSrc = src.split('/');
6
+ transformedSrc.splice(transformedSrc.length - 1, 1, transformedSrc[transformedSrc.length - 1]
7
+ .split(/(?=[A-Z])/)
8
+ .join('_')
9
+ .toLowerCase());
10
+ const url = transformedSrc.join('/');
11
+ return `${root}${url}`;
12
+ };
13
+ exports.imageLoader = imageLoader;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.imageLoader = void 0;
4
+ var image_loader_1 = require("./image_loader");
5
+ Object.defineProperty(exports, "imageLoader", { enumerable: true, get: function () { return image_loader_1.imageLoader; } });
package/dist-cjs/index.js CHANGED
@@ -3,4 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./commander"), exports);
5
5
  tslib_1.__exportStar(require("./constants"), exports);
6
+ tslib_1.__exportStar(require("./images"), exports);
6
7
  tslib_1.__exportStar(require("./page_context"), exports);
@@ -0,0 +1,57 @@
1
+ import { destroyCookie, parseCookies, setCookie } from 'nookies';
2
+ export const defaultHeaders = {
3
+ 'bundle-name': '',
4
+ cur: {
5
+ _id: '5e8c8dfdfca1360007d7b654',
6
+ value: '5e8c8dfdfca1360007d7b654',
7
+ code: 'usd',
8
+ namePlural: 'us dollars',
9
+ symbol: '$',
10
+ },
11
+ hl: 'en',
12
+ 'is-explain': true,
13
+ 'last-activity': 0,
14
+ };
15
+ export const getHeaders = (ctx, options = {}) => {
16
+ let _headers = parseCookies(ctx)['fixefy:headers'];
17
+ _headers = _headers && typeof _headers === 'string' ? JSON.parse(_headers) : typeof _headers === 'object' ? _headers : {};
18
+ const headers = {
19
+ ...defaultHeaders,
20
+ ws: getWorkspace(ctx),
21
+ cur: getCurrency(ctx)._id,
22
+ 'last-activity': getLastActivity(ctx),
23
+ };
24
+ return headers;
25
+ };
26
+ export const setHeaders = (ctx, _headers) => {
27
+ typeof _headers === 'string' ? setCookie(ctx, 'fixefy:headers', { ...JSON.parse(_headers) }, { maxAge: 7 * 24 * 60 * 60, path: '/' }) : setCookie(ctx, 'fixefy:headers', { ..._headers }, { maxAge: 7 * 24 * 60 * 60, path: '/' });
28
+ };
29
+ export const getLastActivity = (ctx) => { };
30
+ export const setLastActivity = (ctx) => { };
31
+ export const flushLastActivity = (ctx) => { };
32
+ export const getWorkspace = (ctx) => {
33
+ const rv = parseCookies(ctx)['ws'] ?? defaultHeaders['ws'];
34
+ return rv;
35
+ };
36
+ export const setWorkspace = (ctx, ws) => {
37
+ setCookie(ctx, 'ws', ws, { maxAge: 7 * 24 * 60 * 60, path: '/' });
38
+ };
39
+ export const flushWorkspace = (ctx) => {
40
+ destroyCookie(ctx, 'ws', { path: '/' });
41
+ };
42
+ export const flushAll = (ctx) => {
43
+ flushLastActivity(ctx);
44
+ flushWorkspace(ctx);
45
+ };
46
+ export const setCurrency = (ctx, currency) => {
47
+ setCookie(ctx, 'cur', JSON.stringify(currency), { maxAge: 7 * 24 * 60 * 60, path: '/' });
48
+ };
49
+ export const getCurrency = (ctx) => {
50
+ const cur = parseCookies(ctx)['cur'] ?? defaultHeaders['cur'];
51
+ if (cur) {
52
+ if (cur === 'usd' || cur === 'eur') {
53
+ setCurrency(ctx, defaultHeaders['cur']);
54
+ }
55
+ return typeof cur === 'string' ? JSON.parse(cur) : cur;
56
+ }
57
+ };
@@ -0,0 +1,9 @@
1
+ export const imageLoader = ({ src, root }) => {
2
+ const transformedSrc = src.split('/');
3
+ transformedSrc.splice(transformedSrc.length - 1, 1, transformedSrc[transformedSrc.length - 1]
4
+ .split(/(?=[A-Z])/)
5
+ .join('_')
6
+ .toLowerCase());
7
+ const url = transformedSrc.join('/');
8
+ return `${root}${url}`;
9
+ };
@@ -0,0 +1 @@
1
+ export { imageLoader } from "./image_loader";
package/dist-es/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './commander';
2
2
  export * from './constants';
3
+ export * from './images';
3
4
  export * from './page_context';
@@ -0,0 +1,12 @@
1
+ export declare const defaultHeaders: any;
2
+ export declare const getHeaders: (ctx: any, options?: {}) => any;
3
+ export declare const setHeaders: (ctx: any, _headers: any) => void;
4
+ export declare const getLastActivity: (ctx: any) => void;
5
+ export declare const setLastActivity: (ctx: any) => void;
6
+ export declare const flushLastActivity: (ctx: any) => void;
7
+ export declare const getWorkspace: (ctx: any) => string;
8
+ export declare const setWorkspace: (ctx: any, ws: string) => void;
9
+ export declare const flushWorkspace: (ctx: any) => void;
10
+ export declare const flushAll: (ctx: any) => void;
11
+ export declare const setCurrency: (ctx: any, currency: JSON) => void;
12
+ export declare const getCurrency: (ctx: any) => any;
@@ -0,0 +1,4 @@
1
+ export declare const imageLoader: ({ src, root }: {
2
+ src: any;
3
+ root: any;
4
+ }) => string;
@@ -0,0 +1 @@
1
+ export { imageLoader } from "./image_loader";
@@ -1,3 +1,4 @@
1
1
  export * from './commander';
2
2
  export * from './constants';
3
+ export * from './images';
3
4
  export * from './page_context';
package/package.json CHANGED
@@ -7,6 +7,7 @@
7
7
  "@mui/material": "^5.14.11",
8
8
  "@mui/styled-engine": "^5.14.11",
9
9
  "@mui/styles": "^5.14.11",
10
+ "nookies": "^2.5.2",
10
11
  "react": "^18.2.0",
11
12
  "react-dom": "^18.2.0"
12
13
  },
@@ -56,5 +57,5 @@
56
57
  }
57
58
  },
58
59
  "types": "./dist-types/index.d.ts",
59
- "version": "0.0.2"
60
- }
60
+ "version": "0.0.4"
61
+ }