@bit.rhplus/data 0.0.2
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 +6 -0
- package/dist/index.js +60 -0
- package/dist/index.js.map +1 -0
- package/dist/preview-1727862136329.js +7 -0
- package/index.js +68 -0
- package/package.json +27 -0
- package/types/asset.d.ts +43 -0
- package/types/style.d.ts +42 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export default function useData(): {
|
|
2
|
+
fetchData: (api: any, data: any) => Promise<any>;
|
|
3
|
+
fetchDataUIAsync: (api: any, data: any) => Promise<any>;
|
|
4
|
+
getFileURL: (content: any, type: any) => string;
|
|
5
|
+
downloadFileURL: (content: any, type: any, fileName: any) => void;
|
|
6
|
+
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { FetchData, errorNotification } from '@rhplus/wieldy.api';
|
|
2
|
+
import { useOidcAccessToken } from "@axa-fr/react-oidc";
|
|
3
|
+
export default function useData() {
|
|
4
|
+
const { accessToken } = useOidcAccessToken();
|
|
5
|
+
const fetchData = (api, data) => FetchData(api, data, accessToken);
|
|
6
|
+
const fetchDataUIAsync = async (api, data) => {
|
|
7
|
+
try {
|
|
8
|
+
const result = await fetchData(api, data);
|
|
9
|
+
return {
|
|
10
|
+
...result,
|
|
11
|
+
result: 'success',
|
|
12
|
+
success: true
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
errorNotification(error);
|
|
17
|
+
return {
|
|
18
|
+
result: 'fail',
|
|
19
|
+
success: false,
|
|
20
|
+
error
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const getFileURL = (content, type) => {
|
|
25
|
+
// Kontrola, zda je `content` base64 řetězec (například zkontrolujeme, jestli obsahuje pouze znaky base64)
|
|
26
|
+
const isBase64 = typeof content === 'string' && /^[A-Za-z0-9+/=]+$/.test(content);
|
|
27
|
+
let byteArray;
|
|
28
|
+
if (isBase64) {
|
|
29
|
+
// Je to base64, převedeme na byteArray
|
|
30
|
+
const byteCharacters = atob(content);
|
|
31
|
+
const byteNumbers = new Array(byteCharacters.length);
|
|
32
|
+
// eslint-disable-next-line no-plusplus
|
|
33
|
+
for (let i = 0; i < byteCharacters.length; i++) {
|
|
34
|
+
byteNumbers[i] = byteCharacters.charCodeAt(i);
|
|
35
|
+
}
|
|
36
|
+
byteArray = new Uint8Array(byteNumbers);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// Očekáváme, že content je již byte array
|
|
40
|
+
byteArray = new Uint8Array(content);
|
|
41
|
+
}
|
|
42
|
+
const blob = new Blob([byteArray], { type });
|
|
43
|
+
const fileUrl = window.URL.createObjectURL(blob);
|
|
44
|
+
return fileUrl;
|
|
45
|
+
};
|
|
46
|
+
const downloadFileURL = (content, type, fileName) => {
|
|
47
|
+
const fileURL = getFileURL(content, type);
|
|
48
|
+
const tempLink = document.createElement("a");
|
|
49
|
+
tempLink.href = fileURL;
|
|
50
|
+
tempLink.download = fileName;
|
|
51
|
+
tempLink.click();
|
|
52
|
+
};
|
|
53
|
+
return {
|
|
54
|
+
fetchData,
|
|
55
|
+
fetchDataUIAsync,
|
|
56
|
+
getFileURL,
|
|
57
|
+
downloadFileURL
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD,MAAM,CAAC,OAAO,UAAU,OAAO;IAE7B,MAAM,EAAE,WAAW,EAAE,GAAG,kBAAkB,EAAE,CAAC;IAC7C,MAAM,SAAS,GAAG,CAAC,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CAAC,OAAO,CAAC,CAAC;QACtC,CAAC;QAED,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;QAC7C,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QACjD,OAAO,OAAO,CAAC;IACjB,CAAC,CAAA;IAED,MAAM,eAAe,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;QAClD,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAC1C,MAAM,QAAQ,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;QAC7C,QAAQ,CAAC,IAAI,GAAG,OAAO,CAAC;QACxB,QAAQ,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAC7B,QAAQ,CAAC,KAAK,EAAE,CAAC;IACnB,CAAC,CAAA;IAED,OAAO;QACL,SAAS;QACT,gBAAgB;QAChB,UAAU;QACV,eAAe;KAChB,CAAA;AACH,CAAC"}
|
package/index.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { FetchData, errorNotification } from '@rhplus/wieldy.api';
|
|
2
|
+
import { useOidcAccessToken } from "@axa-fr/react-oidc";
|
|
3
|
+
|
|
4
|
+
export default function useData() {
|
|
5
|
+
|
|
6
|
+
const { accessToken } = useOidcAccessToken();
|
|
7
|
+
const fetchData = (api, data) => FetchData(api, data, accessToken);
|
|
8
|
+
|
|
9
|
+
const fetchDataUIAsync = async (api, data) => {
|
|
10
|
+
try {
|
|
11
|
+
const result = await fetchData(api, data);
|
|
12
|
+
return {
|
|
13
|
+
...result,
|
|
14
|
+
result: 'success',
|
|
15
|
+
success: true
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
errorNotification(error);
|
|
20
|
+
return {
|
|
21
|
+
result: 'fail',
|
|
22
|
+
success: false,
|
|
23
|
+
error
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const getFileURL = (content, type) => {
|
|
29
|
+
// Kontrola, zda je `content` base64 řetězec (například zkontrolujeme, jestli obsahuje pouze znaky base64)
|
|
30
|
+
const isBase64 = typeof content === 'string' && /^[A-Za-z0-9+/=]+$/.test(content);
|
|
31
|
+
|
|
32
|
+
let byteArray;
|
|
33
|
+
|
|
34
|
+
if (isBase64) {
|
|
35
|
+
// Je to base64, převedeme na byteArray
|
|
36
|
+
const byteCharacters = atob(content);
|
|
37
|
+
const byteNumbers = new Array(byteCharacters.length);
|
|
38
|
+
// eslint-disable-next-line no-plusplus
|
|
39
|
+
for (let i = 0; i < byteCharacters.length; i++) {
|
|
40
|
+
byteNumbers[i] = byteCharacters.charCodeAt(i);
|
|
41
|
+
}
|
|
42
|
+
byteArray = new Uint8Array(byteNumbers);
|
|
43
|
+
} else {
|
|
44
|
+
// Očekáváme, že content je již byte array
|
|
45
|
+
byteArray = new Uint8Array(content);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const blob = new Blob([byteArray], { type });
|
|
49
|
+
const fileUrl = window.URL.createObjectURL(blob);
|
|
50
|
+
return fileUrl;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const downloadFileURL = (content, type, fileName) => {
|
|
54
|
+
const fileURL = getFileURL(content, type);
|
|
55
|
+
const tempLink = document.createElement("a");
|
|
56
|
+
tempLink.href = fileURL;
|
|
57
|
+
tempLink.download = fileName;
|
|
58
|
+
tempLink.click();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
fetchData,
|
|
63
|
+
fetchDataUIAsync,
|
|
64
|
+
getFileURL,
|
|
65
|
+
downloadFileURL
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bit.rhplus/data",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"homepage": "https://bit.cloud/remote-scope/data",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"componentId": {
|
|
7
|
+
"scope": "remote-scope",
|
|
8
|
+
"name": "data",
|
|
9
|
+
"version": "0.0.2"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@axa-fr/react-oidc": "7.19.1",
|
|
13
|
+
"@rhplus/wieldy.api": "0.0.10"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@teambit/react.react-env": "1.0.98"
|
|
17
|
+
},
|
|
18
|
+
"peerDependencies": {},
|
|
19
|
+
"license": "SEE LICENSE IN UNLICENSED",
|
|
20
|
+
"optionalDependencies": {},
|
|
21
|
+
"peerDependenciesMeta": {},
|
|
22
|
+
"private": false,
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"scope": "@bit.rhplus",
|
|
25
|
+
"registry": "https://registry.npmjs.org/"
|
|
26
|
+
}
|
|
27
|
+
}
|
package/types/asset.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
declare module '*.png' {
|
|
2
|
+
const value: any;
|
|
3
|
+
export = value;
|
|
4
|
+
}
|
|
5
|
+
declare module '*.svg' {
|
|
6
|
+
import type { FunctionComponent, SVGProps } from 'react';
|
|
7
|
+
|
|
8
|
+
export const ReactComponent: FunctionComponent<
|
|
9
|
+
SVGProps<SVGSVGElement> & { title?: string }
|
|
10
|
+
>;
|
|
11
|
+
const src: string;
|
|
12
|
+
export default src;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// @TODO Gilad
|
|
16
|
+
declare module '*.jpg' {
|
|
17
|
+
const value: any;
|
|
18
|
+
export = value;
|
|
19
|
+
}
|
|
20
|
+
declare module '*.jpeg' {
|
|
21
|
+
const value: any;
|
|
22
|
+
export = value;
|
|
23
|
+
}
|
|
24
|
+
declare module '*.gif' {
|
|
25
|
+
const value: any;
|
|
26
|
+
export = value;
|
|
27
|
+
}
|
|
28
|
+
declare module '*.bmp' {
|
|
29
|
+
const value: any;
|
|
30
|
+
export = value;
|
|
31
|
+
}
|
|
32
|
+
declare module '*.otf' {
|
|
33
|
+
const value: any;
|
|
34
|
+
export = value;
|
|
35
|
+
}
|
|
36
|
+
declare module '*.woff' {
|
|
37
|
+
const value: any;
|
|
38
|
+
export = value;
|
|
39
|
+
}
|
|
40
|
+
declare module '*.woff2' {
|
|
41
|
+
const value: any;
|
|
42
|
+
export = value;
|
|
43
|
+
}
|
package/types/style.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
declare module '*.module.css' {
|
|
2
|
+
const classes: { readonly [key: string]: string };
|
|
3
|
+
export default classes;
|
|
4
|
+
}
|
|
5
|
+
declare module '*.module.scss' {
|
|
6
|
+
const classes: { readonly [key: string]: string };
|
|
7
|
+
export default classes;
|
|
8
|
+
}
|
|
9
|
+
declare module '*.module.sass' {
|
|
10
|
+
const classes: { readonly [key: string]: string };
|
|
11
|
+
export default classes;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare module '*.module.less' {
|
|
15
|
+
const classes: { readonly [key: string]: string };
|
|
16
|
+
export default classes;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare module '*.less' {
|
|
20
|
+
const classes: { readonly [key: string]: string };
|
|
21
|
+
export default classes;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare module '*.css' {
|
|
25
|
+
const classes: { readonly [key: string]: string };
|
|
26
|
+
export default classes;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare module '*.sass' {
|
|
30
|
+
const classes: { readonly [key: string]: string };
|
|
31
|
+
export default classes;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare module '*.scss' {
|
|
35
|
+
const classes: { readonly [key: string]: string };
|
|
36
|
+
export default classes;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare module '*.mdx' {
|
|
40
|
+
const component: any;
|
|
41
|
+
export default component;
|
|
42
|
+
}
|