ag-common 0.0.307 → 0.0.308
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/dist/ui/helpers/routes.d.ts +10 -6
- package/dist/ui/helpers/routes.js +13 -7
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ICognitoAuth } from './cognito';
|
|
2
2
|
import { AxiosWrapperLite } from './jwt';
|
|
3
3
|
import { TLang } from '../../common/helpers/i18n';
|
|
4
|
+
export declare type TProtocol = 'http:' | 'https:';
|
|
4
5
|
export interface LocationSubset {
|
|
5
6
|
/**
|
|
6
7
|
* slash only path eg /aaa/bbb
|
|
@@ -22,10 +23,7 @@ export interface LocationSubset {
|
|
|
22
23
|
* protocol less up to first slash eg aaa.com:1111
|
|
23
24
|
*/
|
|
24
25
|
host: string;
|
|
25
|
-
|
|
26
|
-
* eg http: or https:
|
|
27
|
-
*/
|
|
28
|
-
protocol: string;
|
|
26
|
+
protocol: TProtocol;
|
|
29
27
|
/**
|
|
30
28
|
* full url
|
|
31
29
|
*/
|
|
@@ -65,7 +63,7 @@ export interface IStateCommon<TRequest extends IRequestCommon> extends IInitialS
|
|
|
65
63
|
* @param param0
|
|
66
64
|
* @returns
|
|
67
65
|
*/
|
|
68
|
-
export declare const getClientOrServerReqHref: ({ url: { href, query }, forceServer, userAgent, darkMode, defaultHost, }: {
|
|
66
|
+
export declare const getClientOrServerReqHref: ({ url: { href, query, protocol }, forceServer, userAgent, darkMode, defaultHost, }: {
|
|
69
67
|
url: {
|
|
70
68
|
/**
|
|
71
69
|
* parse querystring keyvalues
|
|
@@ -75,6 +73,7 @@ export declare const getClientOrServerReqHref: ({ url: { href, query }, forceSer
|
|
|
75
73
|
* full url
|
|
76
74
|
*/
|
|
77
75
|
href?: string | undefined;
|
|
76
|
+
protocol: TProtocol;
|
|
78
77
|
};
|
|
79
78
|
/**
|
|
80
79
|
* if true, wont use window location. default false
|
|
@@ -96,13 +95,14 @@ export declare const getClientOrServerReqHref: ({ url: { href, query }, forceSer
|
|
|
96
95
|
* get server side parsed url
|
|
97
96
|
* @param param0 * @returns
|
|
98
97
|
*/
|
|
99
|
-
export declare const getServerReq: ({ defaultHost, pathname, query, headers, }: {
|
|
98
|
+
export declare const getServerReq: ({ defaultHost, pathname, query, headers, encrypted, }: {
|
|
100
99
|
/**
|
|
101
100
|
* eg ctx?.req?.headers || {}
|
|
102
101
|
*/
|
|
103
102
|
headers: {
|
|
104
103
|
host?: string;
|
|
105
104
|
'user-agent'?: string;
|
|
105
|
+
'x-forwarded-proto'?: 'http' | 'https';
|
|
106
106
|
};
|
|
107
107
|
/** what to use if host is not available on headers */
|
|
108
108
|
defaultHost: string;
|
|
@@ -114,6 +114,10 @@ export declare const getServerReq: ({ defaultHost, pathname, query, headers, }:
|
|
|
114
114
|
* eg ctx.query
|
|
115
115
|
*/
|
|
116
116
|
query: Record<string, string | string[] | undefined>;
|
|
117
|
+
/**
|
|
118
|
+
* eg (ctx?.req?.socket as any)?.encrypted)
|
|
119
|
+
*/
|
|
120
|
+
encrypted: boolean;
|
|
117
121
|
}) => {
|
|
118
122
|
url: LocationSubset;
|
|
119
123
|
userAgent: string;
|
|
@@ -34,10 +34,11 @@ const getRenderLanguage = ({ defaultHost, url, }) => {
|
|
|
34
34
|
* @param param0
|
|
35
35
|
* @returns
|
|
36
36
|
*/
|
|
37
|
-
const getClientOrServerReqHref = ({ url: { href, query }, forceServer = false, userAgent, darkMode, defaultHost, }) => {
|
|
37
|
+
const getClientOrServerReqHref = ({ url: { href, query, protocol }, forceServer = false, userAgent, darkMode, defaultHost, }) => {
|
|
38
38
|
if (typeof window !== 'undefined') {
|
|
39
39
|
if (!forceServer) {
|
|
40
40
|
href = window.location.href;
|
|
41
|
+
protocol = window.location.protocol;
|
|
41
42
|
}
|
|
42
43
|
darkMode =
|
|
43
44
|
window.matchMedia &&
|
|
@@ -53,11 +54,11 @@ const getClientOrServerReqHref = ({ url: { href, query }, forceServer = false, u
|
|
|
53
54
|
const url = {
|
|
54
55
|
hash: parsed.hash || '',
|
|
55
56
|
host: parsed.host || '',
|
|
56
|
-
origin: `${
|
|
57
|
-
href: `${
|
|
57
|
+
origin: `${protocol}//${parsed.host}`,
|
|
58
|
+
href: `${protocol}//${parsed.host}${parsed.path}${parsed.hash || ''}`,
|
|
58
59
|
path: `${parsed.path}${parsed.hash || ''}`,
|
|
59
60
|
pathname: parsed.pathname || '',
|
|
60
|
-
protocol:
|
|
61
|
+
protocol: protocol || '',
|
|
61
62
|
query: Object.assign(Object.assign({}, query), (0, string_1.stringToObject)(parsed.query || '', '=', '&')),
|
|
62
63
|
};
|
|
63
64
|
return {
|
|
@@ -73,12 +74,16 @@ exports.getClientOrServerReqHref = getClientOrServerReqHref;
|
|
|
73
74
|
* get server side parsed url
|
|
74
75
|
* @param param0 * @returns
|
|
75
76
|
*/
|
|
76
|
-
const getServerReq = ({ defaultHost, pathname, query, headers, }) => {
|
|
77
|
-
var _a;
|
|
77
|
+
const getServerReq = ({ defaultHost, pathname, query, headers, encrypted, }) => {
|
|
78
|
+
var _a, _b;
|
|
78
79
|
const href = calculateServerHref({
|
|
79
80
|
host: headers.host || defaultHost,
|
|
80
81
|
pathname,
|
|
81
82
|
});
|
|
83
|
+
let protocol = 'http:';
|
|
84
|
+
if (((_a = headers['x-forwarded-proto']) === null || _a === void 0 ? void 0 : _a.includes('https')) || encrypted) {
|
|
85
|
+
protocol = 'https:';
|
|
86
|
+
}
|
|
82
87
|
const parsedQuery = !query || Object.keys(query).length === 0
|
|
83
88
|
? undefined
|
|
84
89
|
: (0, object_1.castStringlyObject)(query);
|
|
@@ -86,9 +91,10 @@ const getServerReq = ({ defaultHost, pathname, query, headers, }) => {
|
|
|
86
91
|
url: {
|
|
87
92
|
href,
|
|
88
93
|
query: parsedQuery,
|
|
94
|
+
protocol,
|
|
89
95
|
},
|
|
90
96
|
forceServer: true,
|
|
91
|
-
userAgent: (
|
|
97
|
+
userAgent: (_b = headers['user-agent']) === null || _b === void 0 ? void 0 : _b.toLowerCase(),
|
|
92
98
|
defaultHost,
|
|
93
99
|
});
|
|
94
100
|
return ret;
|