@tagsamurai/fats-api-services 1.0.3-alpha.33 → 1.0.3-alpha.34

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.
@@ -3,45 +3,6 @@ const __vite_import_meta_env__ = { "BASE_URL": "/", "DEV": false, "MODE": "produ
3
3
  const getBaseURL = (env = "APP_API") => {
4
4
  return __vite_import_meta_env__["VITE_" + env];
5
5
  };
6
- const createAxiosInstance = (config = {}, useDifferentHeaders = false) => {
7
- const { env = "APP_API", prefix = "", headers = {}, ...restConfig } = config;
8
- const baseURL = `${getBaseURL(env)}${prefix}`;
9
- const instance = axios.create({
10
- ...restConfig,
11
- baseURL,
12
- headers: useDifferentHeaders ? headers : {
13
- "Content-Type": "application/json",
14
- ...headers
15
- }
16
- });
17
- instance.interceptors.request.use((request) => {
18
- const user = JSON.parse(localStorage.getItem("user") ?? "{}");
19
- const jwt = user.jwt ?? user.token ?? "";
20
- request.headers["Authorization"] = `Bearer ${jwt}`;
21
- return request;
22
- });
23
- return instance;
24
- };
25
- const queryParamsStringfy = (data) => {
26
- if (!data || typeof data === "string") {
27
- return;
28
- }
29
- const assignedData = {};
30
- Object.keys(data).forEach((item) => {
31
- if (Array.isArray(data[item])) {
32
- if (data[item].length > 0) {
33
- Object.assign(assignedData, {
34
- [item]: JSON.stringify(data[item])
35
- });
36
- }
37
- } else if (data[item] !== void 0) {
38
- Object.assign(assignedData, {
39
- [item]: data[item]
40
- });
41
- }
42
- });
43
- return assignedData;
44
- };
45
6
  const buildFileURL = (name, width, height) => {
46
7
  const BASE_URL = new URL(getBaseURL("APP_API")).origin;
47
8
  let url = name.startsWith("http") ? name : `${BASE_URL}/file-storage/api/file/${name.replace(/^\/+/, "")}`;
@@ -73,6 +34,9 @@ const fetchBlobFile = async (url, token) => {
73
34
  type: res.headers.get("Content-Type") || "image/webp"
74
35
  });
75
36
  };
37
+ const downloadFile = async (fileUrl) => {
38
+ return createBlobURL(fileUrl);
39
+ };
76
40
  const createBlobURL = async (rawFileUrl) => {
77
41
  try {
78
42
  const token = getAuthToken();
@@ -88,6 +52,45 @@ const getImageURL = async (name, width, height, returnURLOnly) => {
88
52
  if (returnURLOnly) return url;
89
53
  return createBlobURL(url);
90
54
  };
55
+ const createAxiosInstance = (config = {}, useDifferentHeaders = false) => {
56
+ const { env = "APP_API", prefix = "", headers = {}, ...restConfig } = config;
57
+ const baseURL = `${getBaseURL(env)}${prefix}`;
58
+ const instance = axios.create({
59
+ ...restConfig,
60
+ baseURL,
61
+ headers: useDifferentHeaders ? headers : {
62
+ "Content-Type": "application/json",
63
+ ...headers
64
+ }
65
+ });
66
+ instance.interceptors.request.use((request) => {
67
+ const user = JSON.parse(localStorage.getItem("user") ?? "{}");
68
+ const jwt = user.jwt ?? user.token ?? "";
69
+ request.headers["Authorization"] = `Bearer ${jwt}`;
70
+ return request;
71
+ });
72
+ return instance;
73
+ };
74
+ const queryParamsStringfy = (data) => {
75
+ if (!data || typeof data === "string") {
76
+ return;
77
+ }
78
+ const assignedData = {};
79
+ Object.keys(data).forEach((item) => {
80
+ if (Array.isArray(data[item])) {
81
+ if (data[item].length > 0) {
82
+ Object.assign(assignedData, {
83
+ [item]: JSON.stringify(data[item])
84
+ });
85
+ }
86
+ } else if (data[item] !== void 0) {
87
+ Object.assign(assignedData, {
88
+ [item]: data[item]
89
+ });
90
+ }
91
+ });
92
+ return assignedData;
93
+ };
91
94
  const getAssetsFile = async (file, type = "excel") => {
92
95
  const response = await fetch(
93
96
  `${getBaseURL("APP_ASSETS_URL")}/${type}/${file}`
@@ -2734,6 +2737,8 @@ export {
2734
2737
  TransferServicesGo as TransferServices,
2735
2738
  UserServices,
2736
2739
  buildFileURL,
2740
+ downloadFile,
2741
+ fetchBlobFile,
2737
2742
  getAssetsFile,
2738
2743
  getBaseURL,
2739
2744
  getImageURL,
@@ -10,45 +10,6 @@ System.register(["axios"], function(exports, module) {
10
10
  const getBaseURL = exports("getBaseURL", (env = "APP_API") => {
11
11
  return __vite_import_meta_env__["VITE_" + env];
12
12
  });
13
- const createAxiosInstance = (config = {}, useDifferentHeaders = false) => {
14
- const { env = "APP_API", prefix = "", headers = {}, ...restConfig } = config;
15
- const baseURL = `${getBaseURL(env)}${prefix}`;
16
- const instance = axios.create({
17
- ...restConfig,
18
- baseURL,
19
- headers: useDifferentHeaders ? headers : {
20
- "Content-Type": "application/json",
21
- ...headers
22
- }
23
- });
24
- instance.interceptors.request.use((request) => {
25
- const user = JSON.parse(localStorage.getItem("user") ?? "{}");
26
- const jwt = user.jwt ?? user.token ?? "";
27
- request.headers["Authorization"] = `Bearer ${jwt}`;
28
- return request;
29
- });
30
- return instance;
31
- };
32
- const queryParamsStringfy = exports("queryParamsStringfy", (data) => {
33
- if (!data || typeof data === "string") {
34
- return;
35
- }
36
- const assignedData = {};
37
- Object.keys(data).forEach((item) => {
38
- if (Array.isArray(data[item])) {
39
- if (data[item].length > 0) {
40
- Object.assign(assignedData, {
41
- [item]: JSON.stringify(data[item])
42
- });
43
- }
44
- } else if (data[item] !== void 0) {
45
- Object.assign(assignedData, {
46
- [item]: data[item]
47
- });
48
- }
49
- });
50
- return assignedData;
51
- });
52
13
  const buildFileURL = exports("buildFileURL", (name, width, height) => {
53
14
  const BASE_URL = new URL(getBaseURL("APP_API")).origin;
54
15
  let url = name.startsWith("http") ? name : `${BASE_URL}/file-storage/api/file/${name.replace(/^\/+/, "")}`;
@@ -66,7 +27,7 @@ System.register(["axios"], function(exports, module) {
66
27
  const user = JSON.parse(localStorage.getItem("user") ?? "{}");
67
28
  return user.jwt ?? user.token ?? "";
68
29
  };
69
- const fetchBlobFile = async (url, token) => {
30
+ const fetchBlobFile = exports("fetchBlobFile", async (url, token) => {
70
31
  const res = await fetch(url, {
71
32
  headers: {
72
33
  Authorization: `Bearer ${token}`
@@ -79,7 +40,10 @@ System.register(["axios"], function(exports, module) {
79
40
  return new Blob([arrayBuffer], {
80
41
  type: res.headers.get("Content-Type") || "image/webp"
81
42
  });
82
- };
43
+ });
44
+ const downloadFile = exports("downloadFile", async (fileUrl) => {
45
+ return createBlobURL(fileUrl);
46
+ });
83
47
  const createBlobURL = async (rawFileUrl) => {
84
48
  try {
85
49
  const token = getAuthToken();
@@ -95,6 +59,45 @@ System.register(["axios"], function(exports, module) {
95
59
  if (returnURLOnly) return url;
96
60
  return createBlobURL(url);
97
61
  });
62
+ const createAxiosInstance = (config = {}, useDifferentHeaders = false) => {
63
+ const { env = "APP_API", prefix = "", headers = {}, ...restConfig } = config;
64
+ const baseURL = `${getBaseURL(env)}${prefix}`;
65
+ const instance = axios.create({
66
+ ...restConfig,
67
+ baseURL,
68
+ headers: useDifferentHeaders ? headers : {
69
+ "Content-Type": "application/json",
70
+ ...headers
71
+ }
72
+ });
73
+ instance.interceptors.request.use((request) => {
74
+ const user = JSON.parse(localStorage.getItem("user") ?? "{}");
75
+ const jwt = user.jwt ?? user.token ?? "";
76
+ request.headers["Authorization"] = `Bearer ${jwt}`;
77
+ return request;
78
+ });
79
+ return instance;
80
+ };
81
+ const queryParamsStringfy = exports("queryParamsStringfy", (data) => {
82
+ if (!data || typeof data === "string") {
83
+ return;
84
+ }
85
+ const assignedData = {};
86
+ Object.keys(data).forEach((item) => {
87
+ if (Array.isArray(data[item])) {
88
+ if (data[item].length > 0) {
89
+ Object.assign(assignedData, {
90
+ [item]: JSON.stringify(data[item])
91
+ });
92
+ }
93
+ } else if (data[item] !== void 0) {
94
+ Object.assign(assignedData, {
95
+ [item]: data[item]
96
+ });
97
+ }
98
+ });
99
+ return assignedData;
100
+ });
98
101
  const getAssetsFile = exports("getAssetsFile", async (file, type = "excel") => {
99
102
  const response = await fetch(
100
103
  `${getBaseURL("APP_ASSETS_URL")}/${type}/${file}`
package/main.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export { getImageURL as getImageURL, getBaseURL, getAssetsFile, queryParamsStringfy, buildFileURL, } from './src/utils';
1
+ export * from './src/utils/getImageURL.util';
2
+ export { getBaseURL, getAssetsFile, queryParamsStringfy } from './src/utils';
2
3
  export { default as LogServices } from './src/services/log.service';
3
4
  export { default as AssetServices } from './src/services/asset.service';
4
5
  export { default as MissingServices } from './src/services/missing.service';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tagsamurai/fats-api-services",
3
- "version": "1.0.3-alpha.33",
3
+ "version": "1.0.3-alpha.34",
4
4
  "author": "developer.tagsamurai",
5
5
  "description": "Fixed Asset Tag Samurai Services Library",
6
6
  "module": "./api-services.es.js",