@tagsamurai/fats-api-services 2.0.0-alpha.7 → 2.0.0-alpha.9

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.
@@ -99,48 +99,48 @@ const getAssetsFile = async (file, type = "excel") => {
99
99
  );
100
100
  return response;
101
101
  };
102
- const API$1 = createAxiosInstance({
102
+ const API$2 = createAxiosInstance({
103
103
  prefix: "/fam/settings-attribute/v2"
104
104
  });
105
105
  const BrandService = {
106
106
  getBrandList: (params) => {
107
- return API$1.get("/brands", { params });
107
+ return API$2.get("/brands", { params });
108
108
  },
109
109
  createBrand: (body) => {
110
- return API$1.post("/brands", body);
110
+ return API$2.post("/brands", body);
111
111
  },
112
112
  deleteBrand: (body) => {
113
- return API$1.delete("/brands", { data: body });
113
+ return API$2.delete("/brands", { data: body });
114
114
  },
115
115
  getBrandOptions: (params) => {
116
- return API$1.get("/brands/options", { params });
116
+ return API$2.get("/brands/options", { params });
117
117
  },
118
118
  getBrandDropdown: (params) => {
119
- return API$1.get("/brands/dropdown", { params });
119
+ return API$2.get("/brands/dropdown", { params });
120
120
  },
121
121
  getBrandDetail: (id) => {
122
- return API$1.get(`/brands/${id}`);
122
+ return API$2.get(`/brands/${id}`);
123
123
  },
124
124
  editBrand: (id, body) => {
125
- return API$1.put(`/brands/${id}`, body);
125
+ return API$2.put(`/brands/${id}`, body);
126
126
  },
127
127
  getBrandListCategory: (id, params) => {
128
- return API$1.get(`/brands/${id}/list-category`, { params });
128
+ return API$2.get(`/brands/${id}/list-category`, { params });
129
129
  },
130
130
  getBrandListCategoryOptions: (id, params) => {
131
- return API$1.get(`/brands/${id}/list-category/options`, { params });
131
+ return API$2.get(`/brands/${id}/list-category/options`, { params });
132
132
  },
133
133
  getBrandListAsset: (id, params) => {
134
- return API$1.get(`/brands/${id}/list-asset`, { params });
134
+ return API$2.get(`/brands/${id}/list-asset`, { params });
135
135
  },
136
136
  getBrandListAssetOptions: (id, params) => {
137
- return API$1.get(`/brands/${id}/list-asset/options`, { params });
137
+ return API$2.get(`/brands/${id}/list-asset/options`, { params });
138
138
  },
139
139
  assignCategory: (body) => {
140
- return API$1.put("/brands/assign-category", body);
140
+ return API$2.put("/brands/assign-category", body);
141
141
  },
142
142
  unassignCategory: (body) => {
143
- return API$1.put("/brands/unassign-category", body);
143
+ return API$2.put("/brands/unassign-category", body);
144
144
  }
145
145
  };
146
146
  const isValidJSON = (value) => {
@@ -165,28 +165,83 @@ const buildBodyParams = (params) => {
165
165
  });
166
166
  return result;
167
167
  };
168
- const API = createAxiosInstance({
168
+ const API$1 = createAxiosInstance({
169
169
  prefix: "/v2/analytics-reporting"
170
170
  });
171
171
  const ChangelogServices = {
172
172
  getChangelogList: (params) => {
173
173
  const body = buildBodyParams(params);
174
- return API.post("/change-log/list", body);
174
+ return API$1.post("/change-log/list", body);
175
175
  },
176
176
  getChangelogOptions: (body) => {
177
- return API.post("/change-log/options", body);
177
+ return API$1.post("/change-log/options", body);
178
178
  },
179
179
  getSessionLogList: (params) => {
180
180
  const body = buildBodyParams(params);
181
- return API.post("/session-log/list", body);
181
+ return API$1.post("/session-log/list", body);
182
182
  },
183
183
  getSessionLogOptions: (body) => {
184
- return API.post("/session-log/options", body);
184
+ return API$1.post("/session-log/options", body);
185
+ }
186
+ };
187
+ const API = createAxiosInstance({
188
+ env: "APP_GLOBAL_SETTINGS_API",
189
+ prefix: "/v2/iam/auth"
190
+ });
191
+ const onRejected = (error) => {
192
+ if (error.response?.status === 401 || error.response?.status === 500 || error.message === "jwt malformed") {
193
+ window.onblur = void 0;
194
+ window.onfocus = void 0;
195
+ window.sessionExpired = true;
196
+ window.dispatchEvent(new CustomEvent("user:expired"));
197
+ return Promise.reject(error);
198
+ }
199
+ return Promise.reject(error);
200
+ };
201
+ const AuthServices = {
202
+ login: (form) => {
203
+ const body = { ...form, isMobile: false };
204
+ return API.post("/login", body);
205
+ },
206
+ reLogin: (body) => {
207
+ API.interceptors.response.use((response) => {
208
+ return response;
209
+ }, onRejected);
210
+ return API.post("/login", {
211
+ ...body,
212
+ ignoreAccess: true
213
+ // Allow users without access to Global Settings to hit relogin
214
+ });
215
+ },
216
+ requestOTP: (email) => {
217
+ const body = { email };
218
+ return API.post("/request-otp", body);
219
+ },
220
+ requestResetPassLink: (email) => {
221
+ const body = { email };
222
+ return API.post("/request-reset-link", body);
223
+ },
224
+ setPassword: (body) => {
225
+ return API.post("/set-password", body);
226
+ },
227
+ verifyToken: (token) => {
228
+ return API.get(`/verify-token/${token}`);
229
+ },
230
+ confirmEmailChange: (token) => {
231
+ const body = { token };
232
+ return API.post("/confirm-email-change", body);
233
+ },
234
+ cancelEmailChange: (_id) => {
235
+ return API.delete(`cancel-email-change/${_id}`);
236
+ },
237
+ postLogout: () => {
238
+ return API.post("/logout");
185
239
  }
186
240
  };
187
241
  export {
188
242
  BrandService,
189
243
  ChangelogServices,
244
+ AuthServices as GlobalAuthServices,
190
245
  buildFileURL,
191
246
  downloadFile,
192
247
  fetchBlobFile,
package/main.d.ts CHANGED
@@ -2,3 +2,4 @@ export * from './src/utils/getImageURL.util';
2
2
  export { getAssetsFile, getBaseURL } from './src/utils';
3
3
  export { default as BrandService } from './src/services/brand.service';
4
4
  export { default as ChangelogServices } from './src/services/changelog.service';
5
+ export { default as GlobalAuthServices } from './src/services/globalAuth.service';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tagsamurai/fats-api-services",
3
- "version": "2.0.0-alpha.7",
3
+ "version": "2.0.0-alpha.9",
4
4
  "type": "module",
5
5
  "author": "Tagsamurai",
6
6
  "description": "Fixed Asset Tagsamurai API Services",
@@ -0,0 +1,20 @@
1
+ interface Credentials {
2
+ email: string;
3
+ overrideSession: boolean;
4
+ captcha: string;
5
+ agreePolicy: boolean;
6
+ }
7
+ interface PasswordLoginCredentials extends Credentials {
8
+ password: string;
9
+ }
10
+ interface OTPLoginCredentials extends Credentials {
11
+ otp: string;
12
+ }
13
+ export type LoginCredentials = PasswordLoginCredentials | OTPLoginCredentials;
14
+ export interface SetPasswordBody {
15
+ password: string;
16
+ token: string;
17
+ type: SetPasswordType;
18
+ }
19
+ export type SetPasswordType = 'reset' | 'confirm';
20
+ export {};
@@ -1,23 +1,40 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  import { LoginCredentials, SetPasswordBody } from '../dto/globalAuth.dto';
3
+ import { EmailActionResponse } from '../types/emailActionResponse.type';
4
+ import { FetchDetailResponse, FetchResponse } from '../types/fetchResponse.type';
3
5
  interface LoginResponse {
4
- data: {
5
- token: string;
6
- tokenExpiresAt: string;
7
- [key: string]: any;
6
+ _id: string;
7
+ companyName: string;
8
+ companyCode: string;
9
+ fullName: string;
10
+ profilePicture: string;
11
+ email: string;
12
+ isDefault: boolean;
13
+ access: string[];
14
+ generalSetting: {
15
+ dateFormat: string;
16
+ timeFormat: string;
17
+ timezone: string;
18
+ currency: {
19
+ currency: string;
20
+ symbol: string;
21
+ locale: string;
22
+ label: string;
23
+ };
8
24
  };
9
25
  }
10
26
  declare const AuthServices: {
11
- login: (form: LoginCredentials) => Promise<AxiosResponse<LoginResponse>>;
27
+ login: (form: LoginCredentials) => Promise<AxiosResponse<FetchDetailResponse<LoginResponse>>>;
12
28
  reLogin: (body: {
13
29
  jwt: string;
14
30
  }) => 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, {}>>;
31
+ requestOTP: (email: string) => Promise<AxiosResponse<EmailActionResponse<boolean>>>;
32
+ requestResetPassLink: (email: string) => Promise<AxiosResponse<EmailActionResponse<boolean>>>;
33
+ setPassword: (body: SetPasswordBody) => Promise<AxiosResponse<FetchResponse>>;
34
+ verifyToken: (token: string) => Promise<AxiosResponse<FetchDetailResponse<boolean>>>;
35
+ confirmEmailChange: (token: string) => Promise<AxiosResponse<FetchResponse>>;
36
+ cancelEmailChange: (_id: string) => Promise<AxiosResponse<FetchResponse>>;
37
+ postLogout: () => Promise<AxiosResponse<FetchResponse>>;
21
38
  };
22
39
  declare global {
23
40
  interface Window {
@@ -0,0 +1 @@
1
+ export type Data = Record<string, unknown>;
@@ -0,0 +1,6 @@
1
+ import { Data } from './dataTable.type';
2
+ export interface EmailActionResponse<T = Data> {
3
+ status: number;
4
+ message: 'EMAIL_NOT_REGISTERED' | 'INACTIVE_USER' | string;
5
+ data?: T;
6
+ }
@@ -1,17 +1,18 @@
1
+ import { Data } from './dataTable.type';
1
2
  import { Option } from './options.type';
2
- export interface FetchListResponse<T> {
3
+ export type FetchListResponse<T = Data> = {
3
4
  status: number;
4
5
  message: string;
5
6
  data: {
6
- totalRecords: number;
7
7
  data: T[];
8
+ totalRecords: number;
8
9
  };
9
- }
10
- export interface FetchDetailResponse<T> {
10
+ };
11
+ export type FetchDetailResponse<T = Data> = {
11
12
  status: number;
12
13
  message: string;
13
14
  data: T;
14
- }
15
+ };
15
16
  export type FilterOptions<Opt = Record<string, boolean>> = Record<keyof Opt, Option[]>;
16
17
  export type FetchOptionResponse<Opt = Record<string, boolean>> = {
17
18
  message: string;