ag-common 0.0.491 → 0.0.493
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.
|
@@ -10,6 +10,7 @@ export * from './extractAttributes';
|
|
|
10
10
|
export * from './jwt';
|
|
11
11
|
export * from './plural';
|
|
12
12
|
export * from './routes';
|
|
13
|
+
export * from './routesnext';
|
|
13
14
|
export * from './serviceWorker';
|
|
14
15
|
export * from './useContextMenu';
|
|
15
16
|
export * from './useElementAttribute';
|
package/dist/ui/helpers/index.js
CHANGED
|
@@ -26,6 +26,7 @@ __exportStar(require("./extractAttributes"), exports);
|
|
|
26
26
|
__exportStar(require("./jwt"), exports);
|
|
27
27
|
__exportStar(require("./plural"), exports);
|
|
28
28
|
__exportStar(require("./routes"), exports);
|
|
29
|
+
__exportStar(require("./routesnext"), exports);
|
|
29
30
|
__exportStar(require("./serviceWorker"), exports);
|
|
30
31
|
__exportStar(require("./useContextMenu"), exports);
|
|
31
32
|
__exportStar(require("./useElementAttribute"), exports);
|
|
@@ -22,7 +22,6 @@ export interface LocationSubset {
|
|
|
22
22
|
* protocol less up to first slash eg aaa.com:1111
|
|
23
23
|
*/
|
|
24
24
|
host: string;
|
|
25
|
-
protocol: TProtocol;
|
|
26
25
|
/**
|
|
27
26
|
* full url
|
|
28
27
|
*/
|
|
@@ -42,8 +41,8 @@ export interface IInitialStateCommon {
|
|
|
42
41
|
openApiCache?: CacheItem<any>[];
|
|
43
42
|
}
|
|
44
43
|
export interface IRequestCommon {
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
url: URL;
|
|
45
|
+
query: Record<string, string>;
|
|
47
46
|
lang: TLang;
|
|
48
47
|
userAgent: string;
|
|
49
48
|
}
|
|
@@ -55,42 +54,34 @@ export interface IStateCommon<TRequest extends IRequestCommon> extends IInitialS
|
|
|
55
54
|
*/
|
|
56
55
|
cookieDocument: string | undefined;
|
|
57
56
|
}
|
|
57
|
+
export declare const getRenderLanguage: (host?: string | null) => TLang;
|
|
58
58
|
/**
|
|
59
59
|
* get parsed url. use on client/SSR. defaults to window location if possible
|
|
60
60
|
* @param param0
|
|
61
61
|
* @returns
|
|
62
62
|
*/
|
|
63
|
-
export declare const getClientOrServerReqHref: ({ url
|
|
64
|
-
url
|
|
65
|
-
|
|
66
|
-
* parse querystring keyvalues
|
|
67
|
-
*/
|
|
68
|
-
query?: Record<string, string> | undefined;
|
|
69
|
-
/**
|
|
70
|
-
* full url
|
|
71
|
-
*/
|
|
72
|
-
href?: string | undefined;
|
|
73
|
-
protocol: TProtocol;
|
|
74
|
-
};
|
|
63
|
+
export declare const getClientOrServerReqHref: ({ url, query, forceServer, userAgent, }: {
|
|
64
|
+
url?: URL | undefined;
|
|
65
|
+
query?: Record<string, string> | undefined;
|
|
75
66
|
/**
|
|
76
67
|
* if true, wont use window location. default false
|
|
77
68
|
*/
|
|
78
69
|
forceServer?: boolean | undefined;
|
|
79
70
|
/** will use navigator if possible */
|
|
80
71
|
userAgent?: string | undefined;
|
|
81
|
-
/** will use window.matchMedia */
|
|
82
|
-
darkMode?: boolean | undefined;
|
|
83
72
|
}) => {
|
|
84
|
-
url:
|
|
73
|
+
url: URL;
|
|
74
|
+
query: {
|
|
75
|
+
[x: string]: string;
|
|
76
|
+
};
|
|
85
77
|
userAgent: string;
|
|
86
|
-
darkMode: boolean;
|
|
87
78
|
lang: TLang;
|
|
88
79
|
};
|
|
89
80
|
/**
|
|
90
81
|
* get server side parsed url
|
|
91
82
|
* @param param0 * @returns
|
|
92
83
|
*/
|
|
93
|
-
export declare const getServerReq: ({ pathname, query, headers,
|
|
84
|
+
export declare const getServerReq: ({ pathname, query, headers, }: {
|
|
94
85
|
/**
|
|
95
86
|
* eg ctx?.req?.headers || {}
|
|
96
87
|
*/
|
|
@@ -107,13 +98,11 @@ export declare const getServerReq: ({ pathname, query, headers, encrypted, }: {
|
|
|
107
98
|
* eg ctx.query
|
|
108
99
|
*/
|
|
109
100
|
query: Record<string, string | string[] | undefined>;
|
|
110
|
-
/**
|
|
111
|
-
* eg (ctx?.req?.socket as any)?.encrypted)
|
|
112
|
-
*/
|
|
113
|
-
encrypted: boolean;
|
|
114
101
|
}) => {
|
|
115
|
-
url:
|
|
102
|
+
url: URL;
|
|
103
|
+
query: {
|
|
104
|
+
[x: string]: string;
|
|
105
|
+
};
|
|
116
106
|
userAgent: string;
|
|
117
|
-
darkMode: boolean;
|
|
118
107
|
lang: TLang;
|
|
119
108
|
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getServerReq = exports.getClientOrServerReqHref = void 0;
|
|
4
|
-
const url_1 = require("url");
|
|
3
|
+
exports.getServerReq = exports.getClientOrServerReqHref = exports.getRenderLanguage = void 0;
|
|
5
4
|
const i18n_1 = require("../../common/helpers/i18n");
|
|
6
5
|
const object_1 = require("../../common/helpers/object");
|
|
7
6
|
const object_2 = require("../../common/helpers/string/object");
|
|
@@ -19,53 +18,42 @@ const calculateServerHref = ({ host, pathname, }) => {
|
|
|
19
18
|
href += host + pathname;
|
|
20
19
|
return decodeURIComponent(href);
|
|
21
20
|
};
|
|
22
|
-
const getRenderLanguage = (
|
|
23
|
-
var _a, _b, _c
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
const getRenderLanguage = (host) => {
|
|
22
|
+
var _a, _b, _c;
|
|
23
|
+
if (!host) {
|
|
24
|
+
return 'en';
|
|
25
|
+
}
|
|
26
|
+
const prefixReg = new RegExp(`(.*?).(local|${host.toLowerCase()})`, 'gim');
|
|
27
|
+
const host1 = (_b = (_a = host === null || host === void 0 ? void 0 : host.toLowerCase()) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : '';
|
|
28
|
+
const prefix = host.trim().length !== 0 && ((_c = prefixReg.exec(host1)) === null || _c === void 0 ? void 0 : _c[1]);
|
|
27
29
|
if (!prefix) {
|
|
28
30
|
return 'en';
|
|
29
31
|
}
|
|
30
32
|
return (0, i18n_1.getValidatedLang)(prefix);
|
|
31
33
|
};
|
|
34
|
+
exports.getRenderLanguage = getRenderLanguage;
|
|
32
35
|
/**
|
|
33
36
|
* get parsed url. use on client/SSR. defaults to window location if possible
|
|
34
37
|
* @param param0
|
|
35
38
|
* @returns
|
|
36
39
|
*/
|
|
37
|
-
const getClientOrServerReqHref = ({ url
|
|
40
|
+
const getClientOrServerReqHref = ({ url, query, forceServer = false, userAgent, }) => {
|
|
38
41
|
if (typeof window !== 'undefined') {
|
|
39
42
|
if (!forceServer) {
|
|
40
|
-
|
|
41
|
-
protocol = window.location.protocol;
|
|
43
|
+
url = new URL(window.location.href);
|
|
42
44
|
}
|
|
43
|
-
darkMode =
|
|
44
|
-
window.matchMedia &&
|
|
45
|
-
window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
46
45
|
}
|
|
47
46
|
if (typeof navigator !== 'undefined') {
|
|
48
47
|
userAgent = navigator.userAgent;
|
|
49
48
|
}
|
|
50
|
-
if (!
|
|
49
|
+
if (!url) {
|
|
51
50
|
throw new Error('no href');
|
|
52
51
|
}
|
|
53
|
-
const parsed = (0, url_1.parse)(href);
|
|
54
|
-
const url = {
|
|
55
|
-
hash: parsed.hash || '',
|
|
56
|
-
host: parsed.host || '',
|
|
57
|
-
origin: `${protocol}//${parsed.host}`,
|
|
58
|
-
href: `${protocol}//${parsed.host}${parsed.path}${parsed.hash || ''}`,
|
|
59
|
-
path: `${parsed.path}${parsed.hash || ''}`,
|
|
60
|
-
pathname: parsed.pathname || '',
|
|
61
|
-
protocol: protocol || '',
|
|
62
|
-
query: Object.assign(Object.assign({}, query), (0, object_2.stringToObject)(parsed.query || '', '=', '&')),
|
|
63
|
-
};
|
|
64
52
|
return {
|
|
65
53
|
url,
|
|
54
|
+
query: Object.assign(Object.assign({}, query), (0, object_2.stringToObject)(url.search || '', '=', '&')),
|
|
66
55
|
userAgent: userAgent !== null && userAgent !== void 0 ? userAgent : '?',
|
|
67
|
-
|
|
68
|
-
lang: getRenderLanguage({ url }),
|
|
56
|
+
lang: (0, exports.getRenderLanguage)(url.host),
|
|
69
57
|
};
|
|
70
58
|
};
|
|
71
59
|
exports.getClientOrServerReqHref = getClientOrServerReqHref;
|
|
@@ -73,27 +61,18 @@ exports.getClientOrServerReqHref = getClientOrServerReqHref;
|
|
|
73
61
|
* get server side parsed url
|
|
74
62
|
* @param param0 * @returns
|
|
75
63
|
*/
|
|
76
|
-
const getServerReq = ({ pathname, query, headers,
|
|
77
|
-
var _a
|
|
64
|
+
const getServerReq = ({ pathname, query, headers, }) => {
|
|
65
|
+
var _a;
|
|
78
66
|
const href = calculateServerHref({
|
|
79
67
|
host: headers.host || '?',
|
|
80
68
|
pathname,
|
|
81
69
|
});
|
|
82
|
-
|
|
83
|
-
if (((_a = headers['x-forwarded-proto']) === null || _a === void 0 ? void 0 : _a.includes('https')) || encrypted) {
|
|
84
|
-
protocol = 'https:';
|
|
85
|
-
}
|
|
86
|
-
const parsedQuery = !query || Object.keys(query).length === 0
|
|
87
|
-
? undefined
|
|
88
|
-
: (0, object_1.castStringlyObject)(query);
|
|
70
|
+
const parsedQuery = !query || Object.keys(query).length === 0 ? {} : (0, object_1.castStringlyObject)(query);
|
|
89
71
|
const ret = (0, exports.getClientOrServerReqHref)({
|
|
90
|
-
url:
|
|
91
|
-
|
|
92
|
-
query: parsedQuery,
|
|
93
|
-
protocol,
|
|
94
|
-
},
|
|
72
|
+
url: !href ? undefined : new URL(href),
|
|
73
|
+
query: parsedQuery,
|
|
95
74
|
forceServer: true,
|
|
96
|
-
userAgent: (
|
|
75
|
+
userAgent: (_a = headers['user-agent']) === null || _a === void 0 ? void 0 : _a.toLowerCase(),
|
|
97
76
|
});
|
|
98
77
|
return ret;
|
|
99
78
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** next13 server only */
|
|
2
|
+
export declare const getNextAppRequest: ({ headers, searchParams: query, }: {
|
|
3
|
+
searchParams: Record<string, string>;
|
|
4
|
+
/** use next/headers() */
|
|
5
|
+
headers: {
|
|
6
|
+
get: (s: string) => string | null;
|
|
7
|
+
};
|
|
8
|
+
}) => {
|
|
9
|
+
url: URL;
|
|
10
|
+
query: Record<string, string>;
|
|
11
|
+
userAgent: string;
|
|
12
|
+
lang: import("../..").TLang;
|
|
13
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getNextAppRequest = void 0;
|
|
4
|
+
const object_1 = require("../../common/helpers/object");
|
|
5
|
+
const routes_1 = require("./routes");
|
|
6
|
+
/** next13 server only */
|
|
7
|
+
const getNextAppRequest = ({ headers, searchParams: query, }) => {
|
|
8
|
+
var _a, _b, _c, _d;
|
|
9
|
+
const userAgent = (_b = (_a = headers.get('user-agent')) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : '';
|
|
10
|
+
const host = (_c = headers.get('host')) !== null && _c !== void 0 ? _c : '';
|
|
11
|
+
const pathname = (_d = headers.get('x-invoke-path')) !== null && _d !== void 0 ? _d : '/';
|
|
12
|
+
const protocol = host.includes(':443') || !host.includes(':') ? 'https:' : 'http:';
|
|
13
|
+
let url = `${protocol}${host}${pathname}`;
|
|
14
|
+
if (Object.keys(query).length > 0) {
|
|
15
|
+
const qs = '?' + (0, object_1.objectToString)(query, '=', '&');
|
|
16
|
+
url += qs;
|
|
17
|
+
}
|
|
18
|
+
return { url: new URL(url), query, userAgent, lang: (0, routes_1.getRenderLanguage)(host) };
|
|
19
|
+
};
|
|
20
|
+
exports.getNextAppRequest = getNextAppRequest;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.0.
|
|
2
|
+
"version": "0.0.493",
|
|
3
3
|
"name": "ag-common",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
@@ -37,31 +37,31 @@
|
|
|
37
37
|
"typescript": "^5"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@babel/core": "7.22.
|
|
40
|
+
"@babel/core": "7.22.17",
|
|
41
41
|
"@babel/preset-typescript": "7.22.15",
|
|
42
|
-
"@babel/types": "7.22.
|
|
42
|
+
"@babel/types": "7.22.17",
|
|
43
43
|
"@emotion/react": "11.11.1",
|
|
44
44
|
"@emotion/styled": "11.11.0",
|
|
45
45
|
"@smithy/types": "2.3.0",
|
|
46
|
-
"@storybook/addon-actions": "7.4.
|
|
47
|
-
"@storybook/addon-docs": "7.4.
|
|
48
|
-
"@storybook/addon-essentials": "7.4.
|
|
49
|
-
"@storybook/addon-interactions": "7.4.
|
|
50
|
-
"@storybook/addon-links": "7.4.
|
|
51
|
-
"@storybook/addons": "7.4.
|
|
52
|
-
"@storybook/react": "7.4.
|
|
53
|
-
"@storybook/react-webpack5": "7.4.
|
|
54
|
-
"@storybook/theming": "7.4.
|
|
46
|
+
"@storybook/addon-actions": "7.4.1",
|
|
47
|
+
"@storybook/addon-docs": "7.4.1",
|
|
48
|
+
"@storybook/addon-essentials": "7.4.1",
|
|
49
|
+
"@storybook/addon-interactions": "7.4.1",
|
|
50
|
+
"@storybook/addon-links": "7.4.1",
|
|
51
|
+
"@storybook/addons": "7.4.1",
|
|
52
|
+
"@storybook/react": "7.4.1",
|
|
53
|
+
"@storybook/react-webpack5": "7.4.1",
|
|
54
|
+
"@storybook/theming": "7.4.1",
|
|
55
55
|
"@types/jest": "29.5.4",
|
|
56
56
|
"@types/jsonwebtoken": "9.0.2",
|
|
57
|
-
"@types/node": "20.
|
|
57
|
+
"@types/node": "20.6.0",
|
|
58
58
|
"@types/react": "18.2.21",
|
|
59
59
|
"@types/react-dom": "18.2.7",
|
|
60
60
|
"cross-env": "7.0.3",
|
|
61
|
-
"eslint-config-e7npm": "0.0.
|
|
61
|
+
"eslint-config-e7npm": "0.0.35",
|
|
62
62
|
"jest": "29.6.4",
|
|
63
63
|
"rimraf": "5.0.1",
|
|
64
|
-
"storybook": "7.4.
|
|
64
|
+
"storybook": "7.4.1",
|
|
65
65
|
"ts-jest": "29.1.1"
|
|
66
66
|
},
|
|
67
67
|
"files": [
|