@tagsamurai/gsts-api-services 1.0.2-alpha.1 → 1.0.2-alpha.3

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.
@@ -1,33 +1,90 @@
1
- import m from "axios";
2
- const E = { BASE_URL: "/", DEV: !1, MODE: "production", PROD: !0, SSR: !1, VITE_APP_GLOBAL_SETTINGS_API: "https://dev-api.global-settings.tagsamurai.com", VITE_APP_IMAGE_BASE_URL: "https://dev-api.tagsamurai.com/fam/utility/v2/files", VITE_APP_LOGS_NOTIFICATION_API: "https://dev-api-logs-notification.tagsamurai.com", VITE_APP_TAGSAMURAI_API: "https://dev-api.tagsamurai.com" }, _ = (t = "APP_TAGSAMURAI_API") => E["VITE_" + t], o = (t = {}, e = !1) => {
1
+ import _ from "axios";
2
+ const E = { BASE_URL: "/", DEV: !1, MODE: "production", PROD: !0, SSR: !1, VITE_APP_GLOBAL_SETTINGS_API: "https://dev-api.global-settings.tagsamurai.com", VITE_APP_IMAGE_BASE_URL: "https://dev-api.tagsamurai.com/fam/utility/v2/files", VITE_APP_LOGS_NOTIFICATION_API: "https://dev-api-logs-notification.tagsamurai.com", VITE_APP_TAGSAMURAI_API: "https://dev-api.tagsamurai.com" }, T = (t = "APP_TAGSAMURAI_API") => E["VITE_" + t], a = (t = {}, e = !1) => {
3
3
  const {
4
4
  env: r = "APP_GLOBAL_SETTINGS_API",
5
- prefix: c = "",
6
- headers: a = {},
7
- ...l
8
- } = t, g = "".concat(_(r)).concat(c), d = m.create({
9
- ...l,
10
- baseURL: g,
11
- headers: e ? a : {
5
+ prefix: s = "",
6
+ headers: i = {},
7
+ ...p
8
+ } = t, y = "".concat(T(r)).concat(s), A = _.create({
9
+ ...p,
10
+ baseURL: y,
11
+ headers: e ? i : {
12
12
  "Content-Type": "application/json",
13
- ...a
13
+ ...i
14
14
  }
15
15
  });
16
- return d.interceptors.request.use((v) => {
17
- var $, S, I;
18
- const P = JSON.parse(($ = localStorage.getItem("user")) != null ? $ : "{}"), O = (I = (S = P.jwt) != null ? S : P.token) != null ? I : "";
16
+ return A.interceptors.request.use((v) => {
17
+ var f, $, S;
18
+ const P = JSON.parse((f = localStorage.getItem("user")) != null ? f : "{}"), O = (S = ($ = P.jwt) != null ? $ : P.token) != null ? S : "";
19
19
  return v.headers.Authorization = "Bearer ".concat(O), v;
20
- }), d;
21
- }, D = (t, e, r) => {
22
- var l;
23
- if (!t) return;
24
- const c = _("APP_IMAGE_BASE_URL"), a = t.startsWith("http") ? t : "".concat(c, "/").concat(t.replace(/^\/+/, ""));
20
+ }), A;
21
+ }, u = a({
22
+ prefix: "/v1/global-settings/auth"
23
+ }), b = (t) => {
24
+ var e, r, s, i;
25
+ return ((e = t.response) == null ? void 0 : e.status) === 401 || ((r = t.response) == null ? void 0 : r.status) === 500 || ((i = (s = t.response) == null ? void 0 : s.data) == null ? void 0 : i.message) === "jwt malformed" ? (window.onblur = null, window.onfocus = null, window.sessionExpired = !0, window.dispatchEvent(new CustomEvent("user:expired"))) : Promise.reject(t);
26
+ }, x = {
27
+ login: (t) => {
28
+ const e = { ...t, isMobile: !1 };
29
+ return u.post("/login", e);
30
+ },
31
+ reLogin: (t) => (u.interceptors.response.use((e) => e, b), u.post("/login", t)),
32
+ requestOTP: (t) => {
33
+ const e = { email: t };
34
+ return u.post("/request-otp", e);
35
+ },
36
+ requestResetPassLink: (t) => {
37
+ const e = { email: t };
38
+ return u.post("/request-reset-link", e);
39
+ },
40
+ setPassword: (t) => u.post("/set-password", t),
41
+ verifyToken: (t) => u.get("/verify-token/".concat(t)),
42
+ confirmEmailChange: (t) => {
43
+ const e = { token: t };
44
+ return u.put("/confirm-email-change/confirm", e);
45
+ },
46
+ postLogout: () => u.post("/logout"),
47
+ /**
48
+ *
49
+ * @deprecated use postLogout instead
50
+ */
51
+ logout: () => u.post("/logout")
52
+ }, h = (t, e, r) => {
53
+ const s = new URL(T("APP_TAGSAMURAI_API") || "").origin;
54
+ let i = t.startsWith("http") ? t : "".concat(s, "/file-storage/api/file/").concat(t.replace(/^\/+/, ""));
25
55
  if (e || r) {
26
- const g = new URLSearchParams();
27
- return e && g.set("width", e.toString()), r && g.set("height", (l = r == null ? void 0 : r.toString()) != null ? l : e == null ? void 0 : e.toString()), "".concat(a, "?").concat(g.toString());
56
+ const p = new URLSearchParams();
57
+ e && (p.set("width", e.toString()), p.set("height", (r == null ? void 0 : r.toString()) || e.toString())), i += "?".concat(p.toString());
58
+ }
59
+ return i;
60
+ }, L = () => {
61
+ var e, r, s;
62
+ const t = JSON.parse((e = localStorage.getItem("user")) != null ? e : "{}");
63
+ return (s = (r = t.jwt) != null ? r : t.token) != null ? s : "";
64
+ }, R = async (t, e) => {
65
+ const r = await fetch(t, {
66
+ headers: {
67
+ Authorization: "Bearer ".concat(e)
68
+ }
69
+ });
70
+ if (!r.ok)
71
+ throw new Error("Image fetch failed: ".concat(r.status, " ").concat(r.statusText));
72
+ const s = await r.arrayBuffer();
73
+ return new Blob([s], {
74
+ type: r.headers.get("Content-Type") || "image/webp"
75
+ });
76
+ }, w = async (t) => {
77
+ try {
78
+ const e = L(), r = await R(t, e);
79
+ return URL.createObjectURL(r);
80
+ } catch (e) {
81
+ return;
28
82
  }
29
- return a;
30
- }, b = (t) => {
83
+ }, C = async (t, e, r, s) => {
84
+ if (!t) return;
85
+ const i = h(t, e, r);
86
+ return s ? i : w(i);
87
+ }, N = (t) => {
31
88
  if (!t || typeof t == "string")
32
89
  return;
33
90
  const e = {};
@@ -38,141 +95,139 @@ const E = { BASE_URL: "/", DEV: !1, MODE: "production", PROD: !0, SSR: !1, VITE_
38
95
  [r]: t[r]
39
96
  });
40
97
  }), e;
41
- }, G = o({
42
- prefix: "/v1/global-settings/auth"
43
- }), y = () => G.post("/logout"), h = { logout: y }, f = o({
98
+ }, I = a({
44
99
  prefix: "/v1/global-settings/change-log"
45
- }), x = {
46
- getChangelogs: (t) => f.get("", { params: t }),
47
- getChangelogOptions: (t) => f.get("/options", { params: t })
48
- }, u = o({
100
+ }), k = {
101
+ getChangelogs: (t) => I.get("", { params: t }),
102
+ getChangelogOptions: (t) => I.get("/options", { params: t })
103
+ }, c = a({
49
104
  prefix: "/v1/global-settings/division"
50
- }), C = {
51
- getDivisions: (t) => u.get("", { params: t }),
52
- getDivisionDetail: (t) => u.get("/".concat(t)),
53
- postCreateDivision: (t) => u.post("/", t),
54
- putEditDivision: (t, e) => u.put("/".concat(t), e),
105
+ }), B = {
106
+ getDivisions: (t) => c.get("", { params: t }),
107
+ getDivisionDetail: (t) => c.get("/".concat(t)),
108
+ postCreateDivision: (t) => c.post("/", t),
109
+ putEditDivision: (t, e) => c.put("/".concat(t), e),
55
110
  deleteDivisions: (t) => {
56
111
  const e = { id: JSON.stringify(t) };
57
- return u.delete("", { params: e });
112
+ return c.delete("", { params: e });
58
113
  }
59
- }, i = o({
114
+ }, g = a({
60
115
  prefix: "/v1/global-settings"
61
- }), N = {
62
- getTAGAllPaired: (t, e) => i.get("/".concat(t), { params: e }),
63
- getTAGAllPairedOptions: (t, e) => i.get("/".concat(t, "/options"), { params: e }),
64
- getTAGNotPaired: (t, e) => i.get("/".concat(t, "/not-paired"), { params: e }),
65
- getTAGNotPairedOptions: (t, e) => i.get("/".concat(t, "/not-paired/options"), { params: e }),
66
- getScanTAG: (t, e) => i.get("/".concat(t, "/scan"), { params: e }),
67
- putDetailAuditTAG: (t, e) => i.put("/".concat(t, "/audit-detail"), e),
68
- putAuditTAG: (t, e) => i.put("/".concat(t, "/audit"), e),
69
- putAllocateTAG: (t, e) => i.put("/".concat(t, "/allocate"), e),
70
- putCombineTAG: (t) => i.put("/combine", t)
71
- }, s = o({
116
+ }), j = {
117
+ getTAGAllPaired: (t, e) => g.get("/".concat(t), { params: e }),
118
+ getTAGAllPairedOptions: (t, e) => g.get("/".concat(t, "/options"), { params: e }),
119
+ getTAGNotPaired: (t, e) => g.get("/".concat(t, "/not-paired"), { params: e }),
120
+ getTAGNotPairedOptions: (t, e) => g.get("/".concat(t, "/not-paired/options"), { params: e }),
121
+ getScanTAG: (t, e) => g.get("/".concat(t, "/scan"), { params: e }),
122
+ putDetailAuditTAG: (t, e) => g.put("/".concat(t, "/audit-detail"), e),
123
+ putAuditTAG: (t, e) => g.put("/".concat(t, "/audit"), e),
124
+ putAllocateTAG: (t, e) => g.put("/".concat(t, "/allocate"), e),
125
+ putCombineTAG: (t) => g.put("/combine", t)
126
+ }, n = a({
72
127
  prefix: "/v1/global-settings"
73
- }), B = {
74
- getHandheldReader: (t) => s.get("/reader", { params: t }),
75
- getHandheldReaderDetail: (t) => s.get("/reader/".concat(t)),
76
- getHandheldReaderOptions: (t) => s.get("/reader/options", { params: t }),
77
- putMarkHandheldStatus: (t) => s.put("/reader/mark-status", t),
78
- putPingReaders: (t) => s.put("/iot-reader/ping", t),
79
- putMarkIOTStatus: (t, e) => s.put("/".concat(e, "/mark-status"), t),
80
- putEditReaderGroup: (t, e, r) => s.put(
128
+ }), M = {
129
+ getHandheldReader: (t) => n.get("/reader", { params: t }),
130
+ getHandheldReaderDetail: (t) => n.get("/reader/".concat(t)),
131
+ getHandheldReaderOptions: (t) => n.get("/reader/options", { params: t }),
132
+ putMarkHandheldStatus: (t) => n.put("/reader/mark-status", t),
133
+ putPingReaders: (t) => n.put("/iot-reader/ping", t),
134
+ putMarkIOTStatus: (t, e) => n.put("/".concat(e, "/mark-status"), t),
135
+ putEditReaderGroup: (t, e, r) => n.put(
81
136
  "/".concat(t === "iot" ? "iot-" : "", "reader/").concat(r, "/set-group"),
82
137
  e
83
138
  ),
84
- putEditAntennaGroup: (t, e) => s.put("/iot-reader/".concat(e, "/set-port-group"), t),
85
- putEditPortStatus: (t, e) => s.put("/iot-reader/".concat(e, "/set-port-status"), t),
86
- putEditAliasName: (t, e, r) => s.put(
139
+ putEditAntennaGroup: (t, e) => n.put("/iot-reader/".concat(e, "/set-port-group"), t),
140
+ putEditPortStatus: (t, e) => n.put("/iot-reader/".concat(e, "/set-port-status"), t),
141
+ putEditAliasName: (t, e, r) => n.put(
87
142
  "/".concat(t === "iot" ? "iot-" : "", "reader/").concat(r, "/set-alias-name"),
88
143
  e
89
144
  ),
90
- putAntennaPower: (t, e) => s.put("/iot-reader/".concat(e, "/set-antenna-power"), t),
91
- getIOTReaderOrAntenna: (t, e) => s.get("/".concat(t), { params: e }),
92
- getIOTReaderDetail: (t) => s.get("/iot-reader/".concat(t)),
93
- getIOTReaderOrAntennaOptions: (t, e) => s.get("/".concat(t, "/options"), { params: e }),
94
- getActivityLog: (t) => s.get("/activity-log", { params: t }),
95
- getActivityLogOptions: (t) => s.get("/activity-log/options", { params: t }),
96
- getDetailActivityLog: (t) => s.get("/activity-log", { params: t }),
97
- getDetailActivityLogOptions: (t) => s.get("/activity-log/options", { params: t }),
98
- getExistingAliasNames: () => s.get("/reader/alias-names"),
99
- getIotReaderPort: (t, e) => s.get("/iot-reader/".concat(t, "/ports"), { params: e })
100
- }, L = o({
145
+ putAntennaPower: (t, e) => n.put("/iot-reader/".concat(e, "/set-antenna-power"), t),
146
+ getIOTReaderOrAntenna: (t, e) => n.get("/".concat(t), { params: e }),
147
+ getIOTReaderDetail: (t) => n.get("/iot-reader/".concat(t)),
148
+ getIOTReaderOrAntennaOptions: (t, e) => n.get("/".concat(t, "/options"), { params: e }),
149
+ getActivityLog: (t) => n.get("/activity-log", { params: t }),
150
+ getActivityLogOptions: (t) => n.get("/activity-log/options", { params: t }),
151
+ getDetailActivityLog: (t) => n.get("/activity-log", { params: t }),
152
+ getDetailActivityLogOptions: (t) => n.get("/activity-log/options", { params: t }),
153
+ getExistingAliasNames: () => n.get("/reader/alias-names"),
154
+ getIotReaderPort: (t, e) => n.get("/iot-reader/".concat(t, "/ports"), { params: e })
155
+ }, G = a({
101
156
  env: "APP_LOGS_NOTIFICATION_API",
102
157
  prefix: "/v2"
103
- }), M = {
104
- getSessionLogList: (t) => L.get("/session-log", { params: t })
105
- }, T = o({
158
+ }), q = {
159
+ getSessionLogList: (t) => G.get("/session-log", { params: t })
160
+ }, m = a({
106
161
  prefix: "/v1/global-settings/option"
107
- }), j = {
108
- getPositions: () => T.get("/position"),
109
- getDivisions: () => T.get("/division")
110
- }, p = o({
162
+ }), J = {
163
+ getPositions: () => m.get("/position"),
164
+ getDivisions: () => m.get("/division")
165
+ }, l = a({
111
166
  prefix: "/v1/global-settings/position"
112
- }), k = {
113
- getPositions: (t) => p.get("", { params: t }),
114
- getPositionDetail: (t) => p.get("/".concat(t)),
115
- postCreatePosition: (t) => p.post("/", t),
116
- putEditPosition: (t, e) => p.put("/".concat(t), e),
167
+ }), V = {
168
+ getPositions: (t) => l.get("", { params: t }),
169
+ getPositionDetail: (t) => l.get("/".concat(t)),
170
+ postCreatePosition: (t) => l.post("/", t),
171
+ putEditPosition: (t, e) => l.put("/".concat(t), e),
117
172
  deletePositions: (t) => {
118
173
  const e = { id: JSON.stringify(t) };
119
- return p.delete("", { params: e });
174
+ return l.delete("", { params: e });
120
175
  }
121
- }, R = o({
176
+ }, U = a({
122
177
  env: "APP_TAGSAMURAI_API",
123
178
  prefix: "/tag/v2"
124
- }), V = {
125
- getTagInfo: (t) => R.get("/rfid-qr/scan", { params: t })
126
- }, A = o({
127
- prefix: "/v1/global-settings/change-log"
128
179
  }), H = {
129
- getTAGEventlog: (t) => A.get("/tag-event-log", { params: t }),
130
- getTAGEventlogOptions: (t) => A.get("/tag-event-log/options", { params: t }),
131
- getDetailTAGEventlog: (t) => A.get("/tag-event-log/".concat(t))
132
- }, n = o({
180
+ getTagInfo: (t) => U.get("/rfid-qr/scan", { params: t })
181
+ }, d = a({
182
+ prefix: "/v1/global-settings/change-log"
183
+ }), F = {
184
+ getTAGEventlog: (t) => d.get("/tag-event-log", { params: t }),
185
+ getTAGEventlogOptions: (t) => d.get("/tag-event-log/options", { params: t }),
186
+ getDetailTAGEventlog: (t) => d.get("/tag-event-log/".concat(t))
187
+ }, o = a({
133
188
  prefix: "/v1/global-settings/user"
134
- }), J = {
135
- getUsers: (t) => n.get("", { params: t }),
136
- getUserDetail: (t) => n.get("/".concat(t)),
137
- getUserSystemLogs: (t, e) => n.get("/".concat(t, "/system-logs"), { params: e }),
189
+ }), z = {
190
+ getUsers: (t) => o.get("", { params: t }),
191
+ getUserDetail: (t) => o.get("/".concat(t)),
192
+ getUserSystemLogs: (t, e) => o.get("/".concat(t, "/system-logs"), { params: e }),
138
193
  getUserSystemLogOptions: (t, e) => {
139
194
  const r = {};
140
- return r[e] = !0, n.get("/".concat(t, "/system-logs/options"), { params: r });
195
+ return r[e] = !0, o.get("/".concat(t, "/system-logs/options"), { params: r });
141
196
  },
142
197
  postCreateUser: (t) => {
143
198
  const e = { "Content-Type": "multipart/form-data" };
144
- return n.post("", t, { headers: e });
199
+ return o.post("", t, { headers: e });
145
200
  },
146
201
  putEditUser: (t, e) => {
147
202
  const r = { "Content-Type": "multipart/form-data" };
148
- return n.put("/".concat(t), e, { headers: r });
203
+ return o.put("/".concat(t), e, { headers: r });
149
204
  },
150
205
  deleteUsers: (t) => {
151
206
  const e = { id: JSON.stringify(t) };
152
- return n.delete("", { params: e });
207
+ return o.delete("", { params: e });
153
208
  },
154
- putToggleStatusUsers: (t) => n.put("/active-status", t),
209
+ putToggleStatusUsers: (t) => o.put("/active-status", t),
155
210
  getUserOptions: (t) => {
156
211
  const e = {};
157
- return e[t] = !0, n.get("/options", { params: e });
212
+ return e[t] = !0, o.get("/options", { params: e });
158
213
  },
159
- deleteCancelEmailChange: (t) => n.delete("/cancel-email-change/".concat(t)),
160
- postResendEmail: (t) => n.post("/resend-email", t),
161
- putChangePassword: (t, e) => n.put("/change-password/".concat(t), e)
214
+ deleteCancelEmailChange: (t) => o.delete("/cancel-email-change/".concat(t)),
215
+ postResendEmail: (t) => o.post("/resend-email", t),
216
+ putChangePassword: (t, e) => o.put("/change-password/".concat(t), e)
162
217
  };
163
218
  export {
164
- h as AuthServices,
165
- x as ChangelogServices,
166
- C as DivisionServices,
167
- N as GlobalTagServices,
168
- B as HardwareServices,
169
- M as LogServices,
170
- j as OptionServices,
171
- k as PositionServices,
172
- H as TagEventlogServices,
173
- V as TagServices,
174
- J as UserServices,
175
- _ as getBaseURL,
176
- D as getImageURL,
177
- b as queryParamsStringfy
219
+ x as AuthServices,
220
+ k as ChangelogServices,
221
+ B as DivisionServices,
222
+ j as GlobalTagServices,
223
+ M as HardwareServices,
224
+ q as LogServices,
225
+ J as OptionServices,
226
+ V as PositionServices,
227
+ F as TagEventlogServices,
228
+ H as TagServices,
229
+ z as UserServices,
230
+ T as getBaseURL,
231
+ C as getImageURL,
232
+ N as queryParamsStringfy
178
233
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tagsamurai/gsts-api-services",
3
- "version": "1.0.2-alpha.1",
3
+ "version": "1.0.2-alpha.3",
4
4
  "author": "developer.tagsamurai",
5
5
  "description": "Global Settings Tag Samurai Services Library",
6
6
  "module": "./api-services.es.js",
@@ -0,0 +1,18 @@
1
+ interface Credentials {
2
+ email: string;
3
+ dontDeletePreviousSession: boolean;
4
+ }
5
+ interface PasswordLoginCredentials extends Credentials {
6
+ password: string;
7
+ }
8
+ interface OTPLoginCredentials extends Credentials {
9
+ otp: string;
10
+ }
11
+ export type LoginCredentials = PasswordLoginCredentials | OTPLoginCredentials;
12
+ export interface SetPasswordBody {
13
+ password: string;
14
+ token: string;
15
+ type: SetPasswordType;
16
+ }
17
+ export type SetPasswordType = 'reset' | 'confirm';
18
+ export {};
@@ -1,5 +1,32 @@
1
1
  import { AxiosResponse } from 'axios';
2
- declare const _default: {
3
- logout: () => Promise<AxiosResponse>;
2
+ import { LoginCredentials, SetPasswordBody } from '../dto/auth.dto';
3
+ interface LoginResponse {
4
+ data: {
5
+ token: string;
6
+ tokenExpiresAt: string;
7
+ [key: string]: any;
8
+ };
9
+ }
10
+ declare const AuthServices: {
11
+ login: (form: LoginCredentials) => Promise<AxiosResponse<LoginResponse>>;
12
+ reLogin: (body: {
13
+ jwt: string;
14
+ }) => Promise<AxiosResponse<LoginResponse>>;
15
+ requestOTP: (email: string) => Promise<AxiosResponse<any, any>>;
16
+ requestResetPassLink: (email: string) => Promise<AxiosResponse<any, any>>;
17
+ setPassword: (body: SetPasswordBody) => Promise<AxiosResponse<any, any>>;
18
+ verifyToken: (token: string) => Promise<AxiosResponse<any, any>>;
19
+ confirmEmailChange: (token: string) => Promise<AxiosResponse<any, any>>;
20
+ postLogout: () => Promise<AxiosResponse<any, any>>;
21
+ /**
22
+ *
23
+ * @deprecated use postLogout instead
24
+ */
25
+ logout: () => Promise<AxiosResponse<any, any>>;
4
26
  };
5
- export default _default;
27
+ declare global {
28
+ interface Window {
29
+ sessionExpired: boolean;
30
+ }
31
+ }
32
+ export default AuthServices;
@@ -1 +1,11 @@
1
- export declare const getImageURL: (name?: string | null, width?: number, height?: number) => string | undefined;
1
+ export declare const buildFileURL: (name: string, width?: number, height?: number) => string;
2
+ export declare const fetchBlobFile: (url: string, token: string) => Promise<Blob>;
3
+ /**
4
+ *
5
+ * @param fileUrl The full URL
6
+ * @param fileName Custom File name
7
+ * @param immediateRevoke Immediately revoke the object URL after download - default to true
8
+ * @returns
9
+ */
10
+ export declare const downloadFile: (fileUrl: string, fileName: string, immediateRevoke?: boolean) => Promise<string>;
11
+ export declare const getImageURL: (name?: string | null, width?: number, height?: number, returnURLOnly?: boolean) => Promise<string | undefined>;