@ovh-ux/url-builder 1.3.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/CHANGELOG.md +66 -0
- package/README.md +64 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/url-builder.d.ts +9 -0
- package/dist/url-builder.js +51 -0
- package/dist/url-builder.js.map +1 -0
- package/package.json +31 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
# [1.3.0-alpha.0](https://github.com/ovh/manager/compare/@ovh-ux/url-builder@1.2.0...@ovh-ux/url-builder@1.3.0-alpha.0) (2024-10-24)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **manager-react-components:** build manager react components lib ([3ffbfea](https://github.com/ovh/manager/commit/3ffbfeac1e0364917ae6c93f90b392bd1ee6603c))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [1.2.0](https://github.com/ovh/manager/compare/@ovh-ux/url-builder@1.1.1...@ovh-ux/url-builder@1.2.0) (2024-08-08)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* clean dependencies versions of react apps ([7969ba7](https://github.com/ovh/manager/commit/7969ba70f9e03033271a48a5bd0021484ea36263))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## [1.1.1](https://github.com/ovh/manager/compare/@ovh-ux/url-builder@1.1.0...@ovh-ux/url-builder@1.1.1) (2023-01-30)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### Bug Fixes
|
|
32
|
+
|
|
33
|
+
* **url-builder:** add tests ([45afbb6](https://github.com/ovh/manager/commit/45afbb6bea0a0877c4f5b7652d59a7bbbaff3cca))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
# [1.1.0](https://github.com/ovh/manager/compare/@ovh-ux/url-builder@1.0.0...@ovh-ux/url-builder@1.1.0) (2022-11-29)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
### Bug Fixes
|
|
43
|
+
|
|
44
|
+
* **config:** remove unnecessary module resolutions ([e60d83c](https://github.com/ovh/manager/commit/e60d83c343cc15c2f306c1a748c3c06dfa573608))
|
|
45
|
+
* **ts:** fix ts import errors ([58ad060](https://github.com/ovh/manager/commit/58ad060b9d4b6f9634268b5cf4bde98301bbbc98))
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
### Features
|
|
49
|
+
|
|
50
|
+
* **chakra:** add chakra theme and components ([a4ce7ad](https://github.com/ovh/manager/commit/a4ce7adc01f59dcea9d0add60cc6c3ed225c13de))
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
# [1.0.0](https://github.com/ovh/manager/compare/@ovh-ux/url-builder@0.0.0...@ovh-ux/url-builder@1.0.0) (2022-09-12)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
### Features
|
|
60
|
+
|
|
61
|
+
* **url-builder:** add @ovh-ux/url-builder package ([0ef6d33](https://github.com/ovh/manager/commit/0ef6d339eec41b76523b365db4a9328f7bf0fac8))
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
### BREAKING CHANGES
|
|
65
|
+
|
|
66
|
+
* **url-builder:** init @ovh-ux/url-builder package
|
package/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# URL Builder
|
|
2
|
+
|
|
3
|
+
> OVHcloud manager URL Builder
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
yarn add @ovh-ux/url-builder
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
URL builder is here to help us to build links between applications.
|
|
14
|
+
When you want to build an URL for an outside application, you will use `url-builder` to build the URL.
|
|
15
|
+
|
|
16
|
+
### Examples
|
|
17
|
+
|
|
18
|
+
Build the URL that redirect to `#/catalog` state from the `https://www.ovh.com/manager/` base URL with query parameter (`expand`)
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { buildURL } from '@ovh-ux/url-builder';
|
|
22
|
+
|
|
23
|
+
const url = buildURL('https://www.ovh.com/manager/', '#/catalog', {
|
|
24
|
+
expand: true,
|
|
25
|
+
});
|
|
26
|
+
// use `url`;
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Build multiples routes using an array of `{baseURL, path, params}`
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { buildURLs } from '@ovh-ux/url-builder';
|
|
33
|
+
|
|
34
|
+
const [dashboard, catalog] = buildURLs([
|
|
35
|
+
{
|
|
36
|
+
baseURL: 'https://www.ovh.com/manager/',
|
|
37
|
+
path: '#/',
|
|
38
|
+
params: { expand: true },
|
|
39
|
+
},
|
|
40
|
+
{ baseURL: 'https://www.ovh.com/manager/', path: '#/catalog' },
|
|
41
|
+
]);
|
|
42
|
+
// use `dashboard` and `catalog` URLs
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Build multiples routes using an object of `{baseURL, path, params}`
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { buildURLs } from '@ovh-ux/url-builder';
|
|
49
|
+
|
|
50
|
+
const { dashboard, catalog } = buildURLs({
|
|
51
|
+
dashboard: {
|
|
52
|
+
baseURL: 'https://www.ovh.com/manager/',
|
|
53
|
+
path: '#/',
|
|
54
|
+
params: { expand: true },
|
|
55
|
+
},
|
|
56
|
+
catalog: { baseURL: 'https://www.ovh.com/manager/', path: '#/catalog' },
|
|
57
|
+
emailDomainProducts: {
|
|
58
|
+
baseURL: 'https://www.ovh.com/manager/',
|
|
59
|
+
path: '#/:product',
|
|
60
|
+
params: { product: 'email_domain' },
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
// use `dashboard` and `catalog` URLs
|
|
64
|
+
```
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './url-builder';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface OvhURL {
|
|
2
|
+
baseURL: string;
|
|
3
|
+
path: string;
|
|
4
|
+
params: Record<string, ParamValueType>;
|
|
5
|
+
}
|
|
6
|
+
export type ParamValueType = string | number | boolean;
|
|
7
|
+
export declare const buildURL: (baseURL: string, path: string, params: Record<string, ParamValueType>) => string;
|
|
8
|
+
export declare function buildURLs(routes: Array<OvhURL>): Array<OvhURL>;
|
|
9
|
+
export declare function buildURLs(routes: Record<string, OvhURL>): Record<string, OvhURL>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const buildURLPattern = (pattern, params) => {
|
|
2
|
+
let url = pattern;
|
|
3
|
+
let filteredParams = params;
|
|
4
|
+
if (pattern.includes(':') && params) {
|
|
5
|
+
const PARAM_REGEXP = /:(\w+)/g;
|
|
6
|
+
const urlParamTemplates = [...pattern.matchAll(PARAM_REGEXP)].map(([, name]) => name);
|
|
7
|
+
urlParamTemplates.forEach((urlParam) => {
|
|
8
|
+
if (params[urlParam]) {
|
|
9
|
+
url = url.replace(`:${urlParam}`, encodeURIComponent(params[urlParam]));
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
filteredParams = Object.keys(params).reduce((queryParams, paramName) => {
|
|
13
|
+
if (!urlParamTemplates.includes(paramName)) {
|
|
14
|
+
return Object.assign(Object.assign({}, queryParams), { [paramName]: params[paramName] });
|
|
15
|
+
}
|
|
16
|
+
return queryParams;
|
|
17
|
+
}, {});
|
|
18
|
+
}
|
|
19
|
+
return { url, params: filteredParams };
|
|
20
|
+
};
|
|
21
|
+
const buildQueryString = (data) => Object.keys(data)
|
|
22
|
+
.map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(data[key])}`)
|
|
23
|
+
.join('&');
|
|
24
|
+
export const buildURL = (baseURL, path, params) => {
|
|
25
|
+
const urlPattern = buildURLPattern(path, params);
|
|
26
|
+
let { url: buildedPath } = urlPattern;
|
|
27
|
+
const { params: queryObject } = urlPattern;
|
|
28
|
+
if (baseURL.includes('#') && buildedPath.includes('#')) {
|
|
29
|
+
buildedPath = buildedPath.replace('#', '');
|
|
30
|
+
}
|
|
31
|
+
if (baseURL.endsWith('/') && buildedPath.startsWith('/')) {
|
|
32
|
+
buildedPath = buildedPath.substring(1);
|
|
33
|
+
}
|
|
34
|
+
let queryString = queryObject ? buildQueryString(queryObject) : '';
|
|
35
|
+
if (queryString) {
|
|
36
|
+
queryString = buildedPath.includes('?')
|
|
37
|
+
? `&${queryString}`
|
|
38
|
+
: `?${queryString}`;
|
|
39
|
+
}
|
|
40
|
+
return `${baseURL}${buildedPath}${queryString}`;
|
|
41
|
+
};
|
|
42
|
+
export function buildURLs(routes) {
|
|
43
|
+
if (Array.isArray(routes)) {
|
|
44
|
+
return routes.map(({ baseURL, path, params }) => buildURL(baseURL, path, params));
|
|
45
|
+
}
|
|
46
|
+
return Object.keys(routes).reduce((result, name) => {
|
|
47
|
+
const { baseURL, path, params } = routes[name];
|
|
48
|
+
return Object.assign(Object.assign({}, result), { [name]: buildURL(baseURL, path, params) });
|
|
49
|
+
}, {});
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=url-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url-builder.js","sourceRoot":"","sources":["../src/url-builder.ts"],"names":[],"mappings":"AAOA,MAAM,eAAe,GAAG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GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAC9C,QAAQ,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,CAChC,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;QACjD,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QAC/C,uCACK,MAAM,KACT,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IACvC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ovh-ux/url-builder",
|
|
3
|
+
"version": "1.3.0-alpha.0",
|
|
4
|
+
"description": "OVHcloud control panel URL Builder",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/ovh/manager.git",
|
|
8
|
+
"directory": "packages/manager/core/url-builder"
|
|
9
|
+
},
|
|
10
|
+
"license": "BSD-3-Clause",
|
|
11
|
+
"author": "OVH SAS",
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"main": "dist/index.js",
|
|
14
|
+
"module": "dist/index.js",
|
|
15
|
+
"types": "dist/types/index.d.ts",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc",
|
|
21
|
+
"dev": "tsc",
|
|
22
|
+
"dev:watch": "tsc -w",
|
|
23
|
+
"prepare": "tsc",
|
|
24
|
+
"start": "lerna exec --stream --scope='@ovh-ux/url-builder' --include-dependencies -- yarn run build",
|
|
25
|
+
"start:dev": "lerna exec --stream --scope='@ovh-ux/url-builder' --include-dependencies -- yarn run dev",
|
|
26
|
+
"start:watch": "lerna exec --stream --parallel --scope='@ovh-ux/url-builder' --include-dependencies -- yarn run dev:watch"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"typescript": "^5.1.6"
|
|
30
|
+
}
|
|
31
|
+
}
|