@webitel/api-services 0.1.19 → 0.1.21
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/package.json +5 -1
- package/src/enums/RelativeDatetimeValue/RelativeDatetimeValue.ts +11 -0
- package/src/enums/index.ts +2 -1
- package/src/scripts/downloadFile/downloadFile.ts +36 -0
- package/src/scripts/downloadFile/types/downloadFile.types.ts +8 -0
- package/src/scripts/downloadFile/types/fileFormat.types.ts +4 -0
- package/src/scripts/index.ts +2 -1
- package/types/enums/RelativeDatetimeValue/RelativeDatetimeValue.d.ts +7 -0
- package/types/enums/index.d.ts +2 -1
- package/types/scripts/downloadFile/downloadFile.d.ts +3 -0
- package/types/scripts/downloadFile/types/downloadFile.types.d.ts +7 -0
- package/types/scripts/downloadFile/types/fileFormat.types.d.ts +4 -0
- package/types/scripts/index.d.ts +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webitel/api-services",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.21",
|
|
4
4
|
"private": false,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"make-all": "npm run gen:api && npm version patch && (npm run build:types || true) && (npm run format:all || true) && npm run publish-lib",
|
|
@@ -80,6 +80,10 @@
|
|
|
80
80
|
"types": "./types/utils/index.d.ts",
|
|
81
81
|
"import": "./src/utils/index.ts"
|
|
82
82
|
},
|
|
83
|
+
"./scripts": {
|
|
84
|
+
"types": "./types/scripts/index.d.ts",
|
|
85
|
+
"import": "./src/scripts/index.ts"
|
|
86
|
+
},
|
|
83
87
|
"./gen/utils": {
|
|
84
88
|
"types": "./types/utils/gen/index.d.ts",
|
|
85
89
|
"import": "./src/utils/gen/index.ts"
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const valuePrefix = 'rdt'; /* stands for relative datetime */
|
|
2
|
+
|
|
3
|
+
export const RelativeDatetimeValue = {
|
|
4
|
+
Today: `${valuePrefix}_today`,
|
|
5
|
+
ThisWeek: `${valuePrefix}_this_week`,
|
|
6
|
+
ThisMonth: `${valuePrefix}_this_month`,
|
|
7
|
+
Custom: `${valuePrefix}_custom`,
|
|
8
|
+
} as const;
|
|
9
|
+
|
|
10
|
+
export type RelativeDatetimeValue =
|
|
11
|
+
(typeof RelativeDatetimeValue)[keyof typeof RelativeDatetimeValue];
|
package/src/enums/index.ts
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { DownloadFileOptions } from './types/downloadFile.types';
|
|
2
|
+
|
|
3
|
+
const downloadFile = ({
|
|
4
|
+
response,
|
|
5
|
+
fileFormat,
|
|
6
|
+
filename,
|
|
7
|
+
mimetype = null,
|
|
8
|
+
}: DownloadFileOptions) => {
|
|
9
|
+
const blob = new Blob(
|
|
10
|
+
[
|
|
11
|
+
response.data,
|
|
12
|
+
],
|
|
13
|
+
{
|
|
14
|
+
type:
|
|
15
|
+
mimetype ||
|
|
16
|
+
response.headers?.['content-type'] ||
|
|
17
|
+
'application/octet-stream',
|
|
18
|
+
},
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const url = window.URL.createObjectURL(blob);
|
|
22
|
+
const link = document.createElement('a');
|
|
23
|
+
|
|
24
|
+
link.href = url;
|
|
25
|
+
link.download = filename
|
|
26
|
+
? `${filename}.${fileFormat}`
|
|
27
|
+
: `${response.headers?.['Content-Disposition']}.${fileFormat}`;
|
|
28
|
+
|
|
29
|
+
document.body.appendChild(link);
|
|
30
|
+
link.click();
|
|
31
|
+
link.remove();
|
|
32
|
+
|
|
33
|
+
window.URL.revokeObjectURL(url);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export default downloadFile;
|
package/src/scripts/index.ts
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const RelativeDatetimeValue: {
|
|
2
|
+
readonly Today: "rdt_today";
|
|
3
|
+
readonly ThisWeek: "rdt_this_week";
|
|
4
|
+
readonly ThisMonth: "rdt_this_month";
|
|
5
|
+
readonly Custom: "rdt_custom";
|
|
6
|
+
};
|
|
7
|
+
export type RelativeDatetimeValue = (typeof RelativeDatetimeValue)[keyof typeof RelativeDatetimeValue];
|
package/types/enums/index.d.ts
CHANGED
package/types/scripts/index.d.ts
CHANGED