@tagsamurai/gsts-api-services 1.0.2-beta.0 → 1.0.2-beta.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.
@@ -1,33 +1,90 @@
1
- import m from "axios";
2
- const E = { BASE_URL: "/", DEV: !1, MODE: "staging", PROD: !0, SSR: !1, VITE_APP_GLOBAL_SETTINGS_API: "https://staging-api.global-settings.tagsamurai.com", VITE_APP_IMAGE_BASE_URL: "https://staging-api.tagsamurai.com/fam/utility/v2/files", VITE_APP_LOGS_NOTIFICATION_API: "https://staging-api-logs-notification.tagsamurai.com", VITE_APP_TAGSAMURAI_API: "https://staging-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: "staging", PROD: !0, SSR: !1, VITE_APP_GLOBAL_SETTINGS_API: "https://staging-api.global-settings.tagsamurai.com", VITE_APP_IMAGE_BASE_URL: "https://staging-api.tagsamurai.com/fam/utility/v2/files", VITE_APP_LOGS_NOTIFICATION_API: "https://staging-api-logs-notification.tagsamurai.com", VITE_APP_TAGSAMURAI_API: "https://staging-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: n = "",
6
+ headers: i = {},
7
+ ...p
8
+ } = t, y = "".concat(T(r)).concat(n), 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
+ }, g = a({
22
+ prefix: "/v1/global-settings/auth"
23
+ }), b = (t) => {
24
+ var e, r, n, i;
25
+ return ((e = t.response) == null ? void 0 : e.status) === 401 || ((r = t.response) == null ? void 0 : r.status) === 500 || ((i = (n = t.response) == null ? void 0 : n.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 g.post("/login", e);
30
+ },
31
+ reLogin: (t) => (g.interceptors.response.use((e) => e, b), g.post("/login", t)),
32
+ requestOTP: (t) => {
33
+ const e = { email: t };
34
+ return g.post("/request-otp", e);
35
+ },
36
+ requestResetPassLink: (t) => {
37
+ const e = { email: t };
38
+ return g.post("/request-reset-link", e);
39
+ },
40
+ setPassword: (t) => g.post("/set-password", t),
41
+ verifyToken: (t) => g.get("/verify-token/".concat(t)),
42
+ confirmEmailChange: (t) => {
43
+ const e = { token: t };
44
+ return g.put("/confirm-email-change/confirm", e);
45
+ },
46
+ postLogout: () => g.post("/logout"),
47
+ /**
48
+ *
49
+ * @deprecated use postLogout instead
50
+ */
51
+ logout: () => g.post("/logout")
52
+ }, h = (t, e, r) => {
53
+ const n = new URL(T("APP_TAGSAMURAI_API") || "").origin;
54
+ let i = t.startsWith("http") ? t : "".concat(n, "/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, n;
62
+ const t = JSON.parse((e = localStorage.getItem("user")) != null ? e : "{}");
63
+ return (n = (r = t.jwt) != null ? r : t.token) != null ? n : "";
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 n = await r.arrayBuffer();
73
+ return new Blob([n], {
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, n) => {
84
+ if (!t) return;
85
+ const i = h(t, e, r);
86
+ return n ? i : w(i);
87
+ }, N = (t) => {
31
88
  if (!t || typeof t == "string")
32
89
  return;
33
90
  const e = {};
@@ -38,39 +95,37 @@ const E = { BASE_URL: "/", DEV: !1, MODE: "staging", PROD: !0, SSR: !1, VITE_APP
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
+ }, u = 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) => u.get("/".concat(t), { params: e }),
118
+ getTAGAllPairedOptions: (t, e) => u.get("/".concat(t, "/options"), { params: e }),
119
+ getTAGNotPaired: (t, e) => u.get("/".concat(t, "/not-paired"), { params: e }),
120
+ getTAGNotPairedOptions: (t, e) => u.get("/".concat(t, "/not-paired/options"), { params: e }),
121
+ getScanTAG: (t, e) => u.get("/".concat(t, "/scan"), { params: e }),
122
+ putDetailAuditTAG: (t, e) => u.put("/".concat(t, "/audit-detail"), e),
123
+ putAuditTAG: (t, e) => u.put("/".concat(t, "/audit"), e),
124
+ putAllocateTAG: (t, e) => u.put("/".concat(t, "/allocate"), e),
125
+ putCombineTAG: (t) => u.put("/combine", t)
126
+ }, s = a({
72
127
  prefix: "/v1/global-settings"
73
- }), B = {
128
+ }), M = {
74
129
  getHandheldReader: (t) => s.get("/reader", { params: t }),
75
130
  getHandheldReaderDetail: (t) => s.get("/reader/".concat(t)),
76
131
  getHandheldReaderOptions: (t) => s.get("/reader/options", { params: t }),
@@ -97,82 +152,82 @@ const E = { BASE_URL: "/", DEV: !1, MODE: "staging", PROD: !0, SSR: !1, VITE_APP
97
152
  getDetailActivityLogOptions: (t) => s.get("/activity-log/options", { params: t }),
98
153
  getExistingAliasNames: () => s.get("/reader/alias-names"),
99
154
  getIotReaderPort: (t, e) => s.get("/iot-reader/".concat(t, "/ports"), { params: e })
100
- }, L = o({
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-beta.0",
3
+ "version": "1.0.2-beta.2",
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;
@@ -44,6 +44,7 @@ export type UserDetail = {
44
44
  isTemporary: boolean;
45
45
  expiryDate: string;
46
46
  access: string[];
47
+ isConfirmed: boolean;
47
48
  name: string;
48
49
  userTag?: string;
49
50
  isSelf?: boolean;
@@ -62,6 +63,7 @@ export type UserItem = {
62
63
  phoneNumber: string;
63
64
  modifiedBy: ModifiedBy;
64
65
  lastUpdate: string;
66
+ isEmailConfirmed: boolean;
65
67
  isSelf?: boolean;
66
68
  };
67
69
  interface ModifiedBy {
@@ -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>;