@magda/utils 5.4.0-alpha.0 → 5.5.0-alpha.0

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/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Arguments } from 'yargs';
2
+ import { QueryDataMap } from 'urijs';
2
3
 
3
4
  /**
4
5
  * Checks to see whether the passed argv has a jwtSecret object. If not,
@@ -107,6 +108,18 @@ declare interface Functor<T> {
107
108
  map<U>(f: (t: T) => U): Functor<U>;
108
109
  }
109
110
 
111
+ /**
112
+ * Join `url` with `baseUrl` if `url` is not an absolute (full) url string
113
+ *
114
+ * @export
115
+ * @param {string} url A full url string or a url path string (/a/b/c).
116
+ * @param {string} baseUrl A baseUrl used to generate a full url when a url path string is supplied via the `url` parameter.
117
+ * @param {QueryDataMap} [optionalQueries]
118
+ * @param {string[]} [allowedUrlHosts] Optional; when specify, the host of `url` parameter will only be used if it is included by this list.
119
+ * @returns
120
+ */
121
+ export declare function getAbsoluteUrl(url: string, baseUrl: string, optionalQueries?: QueryDataMap, allowedUrlHosts?: string[]): string;
122
+
110
123
  export declare function getDefaultRequestInitOptions(): RequestInit;
111
124
 
112
125
  export declare function getMinikubeIP(): string;
package/dist/index.js CHANGED
@@ -15706,6 +15706,29 @@ function getStorageApiResourceAccessUrl(resourceUrl, storageApiBaseUrl, datasets
15706
15706
  return resourceUrl;
15707
15707
  }
15708
15708
  }
15709
+
15710
+ // ../../magda-typescript-common/dist/getAbsoluteUrl.js
15711
+ init_cjs_shim();
15712
+ var import_urijs2 = __toESM(require_URI(), 1);
15713
+ function getAbsoluteUrl(url2, baseUrl, optionalQueries, allowedUrlHosts) {
15714
+ const uri = (0, import_urijs2.default)(url2);
15715
+ const urlHost = uri.host();
15716
+ if (urlHost) {
15717
+ if (!allowedUrlHosts || allowedUrlHosts.findIndex((item) => item === urlHost) !== -1) {
15718
+ return url2;
15719
+ }
15720
+ }
15721
+ if (typeof baseUrl !== "string") {
15722
+ baseUrl = "";
15723
+ }
15724
+ const baseUri = (0, import_urijs2.default)(baseUrl);
15725
+ const query = uri.search(true);
15726
+ const mergedUri = baseUri.segmentCoded(baseUri.segmentCoded().concat(uri.segmentCoded()));
15727
+ return mergedUri.search({
15728
+ ...query ? query : {},
15729
+ ...optionalQueries ? optionalQueries : {}
15730
+ }).toString();
15731
+ }
15709
15732
  export {
15710
15733
  AsyncPage,
15711
15734
  BadRequestError,
@@ -15721,6 +15744,7 @@ export {
15721
15744
  fetchRequest,
15722
15745
  forEachAsync,
15723
15746
  formatServiceError,
15747
+ getAbsoluteUrl,
15724
15748
  getDefaultRequestInitOptions,
15725
15749
  getMinikubeIP,
15726
15750
  getRequest,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@magda/utils",
3
3
  "description": "MAGDA Common Utils",
4
- "version": "5.4.0-alpha.0",
4
+ "version": "5.5.0-alpha.0",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
@@ -26,7 +26,7 @@
26
26
  "module": "dist/index.js",
27
27
  "browser": "dist/index-web.js",
28
28
  "devDependencies": {
29
- "@magda/typescript-common": "^5.4.0-alpha.0",
29
+ "@magda/typescript-common": "^5.5.0-alpha.0",
30
30
  "@microsoft/api-extractor": "~7.39.0",
31
31
  "esbuild": "^0.19.10",
32
32
  "ts-loader": "^9.5.1",