ag-common 0.0.149 → 0.0.150

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.
@@ -67,7 +67,7 @@ export interface IStateCommon<TRequest extends IRequestCommon> extends IInitialS
67
67
  * @param param0
68
68
  * @returns
69
69
  */
70
- export declare const getClientOrServerReqHref: ({ href, query, }: {
70
+ export declare const getClientOrServerReqHref: ({ href, query, forceServer, }: {
71
71
  /**
72
72
  * will use window if possible
73
73
  */
@@ -76,6 +76,10 @@ export declare const getClientOrServerReqHref: ({ href, query, }: {
76
76
  * pass in query string params
77
77
  */
78
78
  query?: Record<string, string> | undefined;
79
+ /**
80
+ * if true, wont use window location. default false
81
+ */
82
+ forceServer?: boolean | undefined;
79
83
  }) => LocationSubset;
80
84
  /**
81
85
  * get server side parsed url
@@ -83,7 +87,7 @@ export declare const getClientOrServerReqHref: ({ href, query, }: {
83
87
  */
84
88
  export declare const getServerReq: ({ host, pathname, query, }: {
85
89
  /**
86
- * eg ctx?.req?.headers?.host
90
+ * eg ctx?.req?.headers?.host OR (user provided host eg test.com)
87
91
  */
88
92
  host: string;
89
93
  /**
@@ -104,4 +108,3 @@ export interface INextCtx {
104
108
  asPath?: string;
105
109
  query: Record<string, string | string[] | undefined>;
106
110
  }
107
- export declare const getServerReqNextJs: (ctx: INextCtx) => LocationSubset | null;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getServerReqNextJs = exports.getServerReq = exports.getClientOrServerReqHref = void 0;
3
+ exports.getServerReq = exports.getClientOrServerReqHref = void 0;
4
4
  const url_1 = require("url");
5
5
  const string_1 = require("../../common/helpers/string");
6
6
  const object_1 = require("../../common/helpers/object");
@@ -23,8 +23,8 @@ const calculateServerHref = ({ host, pathname, }) => {
23
23
  * @param param0
24
24
  * @returns
25
25
  */
26
- const getClientOrServerReqHref = ({ href, query, }) => {
27
- if (typeof window !== 'undefined') {
26
+ const getClientOrServerReqHref = ({ href, query, forceServer = false, }) => {
27
+ if (typeof window !== 'undefined' && !forceServer) {
28
28
  href = window.location.href;
29
29
  }
30
30
  if (!href) {
@@ -56,17 +56,11 @@ const getServerReq = ({ host, pathname, query, }) => {
56
56
  const parsedQuery = !query || Object.keys(query).length === 0
57
57
  ? undefined
58
58
  : (0, object_1.castStringlyObject)(query);
59
- const ret = (0, exports.getClientOrServerReqHref)({ href, query: parsedQuery });
59
+ const ret = (0, exports.getClientOrServerReqHref)({
60
+ href,
61
+ query: parsedQuery,
62
+ forceServer: true,
63
+ });
60
64
  return ret;
61
65
  };
62
66
  exports.getServerReq = getServerReq;
63
- const getServerReqNextJs = (ctx) => {
64
- var _a, _b;
65
- const host = (_b = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.req) === null || _a === void 0 ? void 0 : _a.headers) === null || _b === void 0 ? void 0 : _b.host;
66
- const pathname = ctx === null || ctx === void 0 ? void 0 : ctx.asPath;
67
- if (!host || !pathname) {
68
- return null;
69
- }
70
- return (0, exports.getServerReq)({ host, pathname, query: ctx.query });
71
- };
72
- exports.getServerReqNextJs = getServerReqNextJs;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ag-common",
3
- "version": "0.0.149",
3
+ "version": "0.0.150",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Andrei Gec <@andreigec> (https://gec.dev/)",