@abcagency/hire-control-sdk 1.0.9 → 1.0.10

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,6 +1,6 @@
1
- import FetchHandler from '../handlers/fetchHandler';
2
- import Event from '../types/event';
3
- import { API_URL } from '../constants/config';
1
+ import FetchHandler from "../handlers/fetchHandler";
2
+ import Event from "../types/event";
3
+ import { API_URL } from "../constants/config";
4
4
 
5
5
  const fetchHandler = new FetchHandler(API_URL);
6
6
 
@@ -10,7 +10,7 @@ class EventsController {
10
10
  * @returns {Promise<Event[]>} - A list of events.
11
11
  */
12
12
  async getEvents(authToken: string | null = null): Promise<Event[]> {
13
- return fetchHandler.get<Event[]>('/events', true, authToken);
13
+ return fetchHandler.get<Event[]>("/events", true, authToken);
14
14
  }
15
15
 
16
16
  /**
@@ -30,7 +30,7 @@ class EventsController {
30
30
  * @returns {Promise<Event>} - The newly created event data.
31
31
  */
32
32
  async createEvent(Event: any, authToken: string | null = null): Promise<any> {
33
- return fetchHandler.post<any, any>('/events', Event, true, authToken);
33
+ return fetchHandler.post<any, any>("/events", Event, true, authToken, true);
34
34
  }
35
35
 
36
36
  /**
@@ -40,8 +40,18 @@ class EventsController {
40
40
  * @param {string | null} authToken - Optional auth token.
41
41
  * @returns {Promise<void>} - No return value.
42
42
  */
43
- async updateEvent(id: string, Event: Event, authToken: string | null = null): Promise<void> {
44
- return fetchHandler.put<Event, void>(`/events/${id}`, Event, true, authToken);
43
+ async updateEvent(
44
+ id: string,
45
+ Event: Event,
46
+ authToken: string | null = null
47
+ ): Promise<void> {
48
+ return fetchHandler.put<Event, void>(
49
+ `/events/${id}`,
50
+ Event,
51
+ true,
52
+ authToken,
53
+ true
54
+ );
45
55
  }
46
56
 
47
57
  /**
@@ -50,7 +60,10 @@ class EventsController {
50
60
  * @param {string | null} authToken - Optional auth token.
51
61
  * @returns {Promise<void>} - No return value.
52
62
  */
53
- async deleteEvent(id: string, authToken: string | null = null): Promise<void> {
63
+ async deleteEvent(
64
+ id: string,
65
+ authToken: string | null = null
66
+ ): Promise<void> {
54
67
  return fetchHandler.delete(`/events/${id}`, true, authToken);
55
68
  }
56
69
  }
@@ -1,4 +1,4 @@
1
- import Event from '../types/event';
1
+ import Event from "../types/event";
2
2
  declare class EventsController {
3
3
  /**
4
4
  * Get all events for the authenticated user’s company.
@@ -2,9 +2,10 @@ declare class FetchHandler {
2
2
  private apiUrl;
3
3
  constructor(apiUrl: string);
4
4
  get<T>(endpoint: string, auth?: boolean, authToken?: string | null): Promise<T>;
5
- post<T, R>(endpoint: string, body: T, auth?: boolean, authToken?: string | null): Promise<R>;
6
- put<T, R>(endpoint: string, body: T, auth?: boolean, authToken?: string | null): Promise<R>;
5
+ post<T, R>(endpoint: string, body: T, auth?: boolean, authToken?: string | null, formData?: boolean): Promise<R>;
6
+ put<T, R>(endpoint: string, body: T, auth?: boolean, authToken?: string | null, formData?: boolean): Promise<R>;
7
7
  delete<T>(endpoint: string, auth?: boolean, authToken?: string | null): Promise<T>;
8
+ private convertToFormData;
8
9
  private fetchWithoutAuth;
9
10
  private fetchWithAuth;
10
11
  private handleResponse;
package/dist/index.cjs.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("tslib");class e{constructor(t){this.apiUrl=t}get(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=!1,r=null){const n={method:"GET",credentials:"include"};return e?this.fetchWithAuth(t,n,r):this.fetchWithoutAuth(t,n)}))}post(e,r){return t.__awaiter(this,arguments,void 0,(function*(t,e,r=!1,n=null){const i={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e),credentials:"include"};return r?this.fetchWithAuth(t,i,n):this.fetchWithoutAuth(t,i)}))}put(e,r){return t.__awaiter(this,arguments,void 0,(function*(t,e,r=!1,n=null){const i={method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e),credentials:"include"};return r?this.fetchWithAuth(t,i,n):this.fetchWithoutAuth(t,i)}))}delete(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=!1,r=null){const n={method:"DELETE",credentials:"include"};return e?this.fetchWithAuth(t,n,r):this.fetchWithoutAuth(t,n)}))}fetchWithoutAuth(e,r){return t.__awaiter(this,void 0,void 0,(function*(){const t=yield fetch(`${this.apiUrl}${e}`,r);return this.handleResponse(t)}))}fetchWithAuth(e,r,n){return t.__awaiter(this,void 0,void 0,(function*(){n&&(r.headers=Object.assign(Object.assign({},r.headers),{Authorization:`Bearer ${n}`}));let t=yield fetch(`${this.apiUrl}${e}`,r);if(401===t.status){if(!(yield this.refreshToken()))throw new Error("Token refresh failed");t=yield fetch(`${this.apiUrl}${e}`,r)}return this.handleResponse(t)}))}handleResponse(e){return t.__awaiter(this,void 0,void 0,(function*(){if(!e.ok||!e.status.toString().startsWith("2")){let t=`Error: ${e.status} ${e.statusText}`;try{const r=yield e.json();console.log(r),r&&r.message&&(t=r.message)}catch(t){console.error("Failed to parse error response:",t)}throw{statusCode:e.status,errorMessage:t}}return 200==e.status?e.json():null}))}refreshToken(){return t.__awaiter(this,void 0,void 0,(function*(){return!!(yield fetch(`${this.apiUrl}/auth/refresh`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include"})).ok||(console.error("Failed to refresh token"),!1)}))}}const r="https://api.myhirecontrol.com",n=new e(r);var i=new class{login(e){return t.__awaiter(this,void 0,void 0,(function*(){return n.post("/auth/login",e,!1)}))}nextLogin(e){return t.__awaiter(this,void 0,void 0,(function*(){return yield n.post("/auth/nextLogin",e,!1)}))}refreshToken(e){return t.__awaiter(this,void 0,void 0,(function*(){const t=yield n.post("/auth/refresh",e,!1);return t&&(sessionStorage.setItem("token",t.token),sessionStorage.setItem("refreshToken",t.refreshToken),sessionStorage.setItem("expiration",t.expiration)),t}))}changeCompany(e){return t.__awaiter(this,void 0,void 0,(function*(){return n.post("/auth/changeCompany",e,!0)}))}register(e){return t.__awaiter(this,void 0,void 0,(function*(){return n.post("/auth/register",e,!1)}))}getCompanies(){return t.__awaiter(this,void 0,void 0,(function*(){return n.get("/auth/companies",!0)}))}getCompany(){return t.__awaiter(this,void 0,void 0,(function*(){return n.get("/auth/company",!0)}))}getRoles(){return t.__awaiter(this,void 0,void 0,(function*(){return n.get("/auth/roles",!0)}))}isAuthenticated(){return t.__awaiter(this,void 0,void 0,(function*(){try{return yield n.get("/auth/authenticated",!0)}catch(t){return!1}}))}getUser(){return t.__awaiter(this,arguments,void 0,(function*(t=null){try{return yield n.get("/auth/user",!0,t)}catch(t){throw t}}))}logout(){return t.__awaiter(this,void 0,void 0,(function*(){try{const t=yield n.post("/auth/logout",{},!0);return sessionStorage.removeItem("token"),sessionStorage.removeItem("refreshToken"),sessionStorage.removeItem("expiration"),t}catch(t){throw t}}))}getPermissions(){return t.__awaiter(this,arguments,void 0,(function*(t=null){try{return yield n.get("/auth/permissions",!0,t)}catch(t){throw t}}))}};const o=new e(r);var s=new class{getEvents(){return t.__awaiter(this,arguments,void 0,(function*(t=null){return o.get("/events",!0,t)}))}getEvent(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return o.get(`/events/${t}`,!0,e)}))}createEvent(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return o.post("/events",t,!0,e)}))}updateEvent(e,r){return t.__awaiter(this,arguments,void 0,(function*(t,e,r=null){return o.put(`/events/${t}`,e,!0,r)}))}deleteEvent(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return o.delete(`/events/${t}`,!0,e)}))}};const u=new e(r);var a=new class{getAllRolesWithClaims(){return t.__awaiter(this,arguments,void 0,(function*(t=null){return u.get("/roles",!0,t)}))}addRole(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return u.post("/roles",t,!0,e)}))}updateRole(e,r){return t.__awaiter(this,arguments,void 0,(function*(t,e,r=null){return u.put(`/roles/${t}`,e,!0,r)}))}deleteRole(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return u.delete(`/roles/${t}`,!0,e)}))}};const l=new e(r);var h=new class{getAllUsers(){return t.__awaiter(this,arguments,void 0,(function*(t=null){try{return yield l.get("/users",!0,t)}catch(t){throw t}}))}getUser(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){try{return yield l.get(`/users/${t}`,!0,e)}catch(t){throw t}}))}createUser(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){try{return yield l.post("/users",t,!0,e)}catch(t){throw t}}))}updateUser(e,r){return t.__awaiter(this,arguments,void 0,(function*(t,e,r=null){try{yield l.put(`/users/${t}`,e,!0,r)}catch(t){throw t}}))}updateLoggedInUser(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){try{yield l.put("/users",t,!0,e)}catch(t){throw t}}))}deleteUser(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){try{yield l.delete(`/users/${t}`,!0,e)}catch(t){throw t}}))}};const c=new e(r);var d=new class{forgotPassword(e){return t.__awaiter(this,void 0,void 0,(function*(){try{return yield c.post("/account/forgotPassword",e,!1)}catch(t){throw t}}))}resetPasswordWithToken(e){return t.__awaiter(this,void 0,void 0,(function*(){try{return yield c.post("/account/resetPasswordWithToken",e,!1)}catch(t){throw t}}))}resetPassword(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){try{return yield c.post("/account/resetPassword",t,!0,e)}catch(t){throw t}}))}};const g=new e(r);var f=new class{getMapConfig(){return t.__awaiter(this,arguments,void 0,(function*(t=null){try{return yield g.get("/mapconfig",!0,t)}catch(t){throw t}}))}updateMapConfig(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return g.put("/mapconfig",t,!0,e)}))}createMapConfig(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return g.post("/mapconfig",t,!0,e)}))}};const _=new e(r);var p=new class{getAllPermissions(){return t.__awaiter(this,arguments,void 0,(function*(t=null){return _.get("/permissions",!0,t)}))}};const w=new e(r);var v=new class{getClientAuthConfigById(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){try{return yield w.get(`/clientAuthConfig/${t}`,!0,e)}catch(t){throw t}}))}getAllClientAuthConfigs(){return t.__awaiter(this,arguments,void 0,(function*(t=null){try{return yield w.get("/clientAuthConfig",!0,t)}catch(t){throw t}}))}createClientAuthConfig(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return w.post("/clientAuthConfig",t,!0,e)}))}updateClientAuthConfig(e,r){return t.__awaiter(this,arguments,void 0,(function*(t,e,r=null){return w.put(`/clientAuthConfig/${t}`,e,!0,r)}))}deleteClientAuthConfig(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return w.delete(`/clientAuthConfig/${t}`,!0,e)}))}};const y=new e(r);var C=new class{getListings(){return t.__awaiter(this,arguments,void 0,(function*(t=null){try{return yield y.get("/listings",!0,t)}catch(t){throw t}}))}getListingDetails(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){try{return yield y.get(`/listings/${t}`,!0,e)}catch(t){throw t}}))}};const m={login:i.login,nextLogin:i.nextLogin,refreshToken:i.refreshToken,changeCompany:i.changeCompany,register:i.register,isAuthenticated:i.isAuthenticated,getCompany:i.getCompany,getCompanies:i.getCompanies,getRoles:i.getRoles,getPermissions:i.getPermissions,logout:i.logout,getUser:i.getUser},A={getAll:s.getEvents,get:s.getEvent,create:s.createEvent,update:s.updateEvent,delete:s.deleteEvent},T={get:a.getAllRolesWithClaims,create:a.addRole,update:a.updateRole,delete:a.deleteRole},$=h,P=C,k={resetPassword:d.resetPassword,resetPasswordWithToken:d.resetPasswordWithToken,forgotPassword:d.forgotPassword},x={get:f.getMapConfig,update:f.updateMapConfig,create:f.createMapConfig},W={get:v.getClientAuthConfigById,getAll:v.getAllClientAuthConfigs,update:v.updateClientAuthConfig,create:v.createClientAuthConfig,delete:v.deleteClientAuthConfig},E={get:p.getAllPermissions},U={auth:m,events:A,roles:T,users:$,account:k,mapConfig:x,permissions:E,clientAuthConfig:W,listings:P};exports.account=k,exports.auth=m,exports.clientAuthConfig=W,exports.default=U,exports.events=A,exports.listings=P,exports.mapConfig=x,exports.permissions=E,exports.roles=T,exports.users=$;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("tslib");class e{constructor(t){this.apiUrl=t}get(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=!1,r=null){const n={method:"GET",credentials:"include"};return e?this.fetchWithAuth(t,n,r):this.fetchWithoutAuth(t,n)}))}post(e,r){return t.__awaiter(this,arguments,void 0,(function*(t,e,r=!1,n=null,i=!1){const o={method:"POST",credentials:"include"};return i?o.body=this.convertToFormData(e):(o.headers={"Content-Type":"application/json"},o.body=JSON.stringify(e)),r?this.fetchWithAuth(t,o,n):this.fetchWithoutAuth(t,o)}))}put(e,r){return t.__awaiter(this,arguments,void 0,(function*(t,e,r=!1,n=null,i=!1){const o={method:"PUT",credentials:"include"};return i?o.body=this.convertToFormData(e):(o.headers={"Content-Type":"application/json"},o.body=JSON.stringify(e)),r?this.fetchWithAuth(t,o,n):this.fetchWithoutAuth(t,o)}))}delete(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=!1,r=null){const n={method:"DELETE",credentials:"include"};return e?this.fetchWithAuth(t,n,r):this.fetchWithoutAuth(t,n)}))}convertToFormData(t,e=new FormData,r=""){return t instanceof File||"string"==typeof t||"number"==typeof t||"boolean"==typeof t?e.append(r,t):t instanceof Array?t.forEach(((t,n)=>{this.convertToFormData(t,e,`${r}[${n}]`)})):t instanceof Object&&Object.keys(t).forEach((n=>{const i=t[n],o=r?`${r}[${n}]`:n;this.convertToFormData(i,e,o)})),e}fetchWithoutAuth(e,r){return t.__awaiter(this,void 0,void 0,(function*(){const t=yield fetch(`${this.apiUrl}${e}`,r);return this.handleResponse(t)}))}fetchWithAuth(e,r,n){return t.__awaiter(this,void 0,void 0,(function*(){n&&(r.headers=Object.assign(Object.assign({},r.headers),{Authorization:`Bearer ${n}`}));let t=yield fetch(`${this.apiUrl}${e}`,r);if(401===t.status){if(!(yield this.refreshToken()))throw new Error("Token refresh failed");t=yield fetch(`${this.apiUrl}${e}`,r)}return this.handleResponse(t)}))}handleResponse(e){return t.__awaiter(this,void 0,void 0,(function*(){if(!e.ok||!e.status.toString().startsWith("2")){let t=`Error: ${e.status} ${e.statusText}`;try{const r=yield e.json();console.log(r),r&&r.message&&(t=r.message)}catch(t){console.error("Failed to parse error response:",t)}throw{statusCode:e.status,errorMessage:t}}return 200===e.status?e.json():null}))}refreshToken(){return t.__awaiter(this,void 0,void 0,(function*(){return!!(yield fetch(`${this.apiUrl}/auth/refresh`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include"})).ok||(console.error("Failed to refresh token"),!1)}))}}const r="https://api.myhirecontrol.com",n=new e(r);var i=new class{login(e){return t.__awaiter(this,void 0,void 0,(function*(){return n.post("/auth/login",e,!1)}))}nextLogin(e){return t.__awaiter(this,void 0,void 0,(function*(){return yield n.post("/auth/nextLogin",e,!1)}))}refreshToken(e){return t.__awaiter(this,void 0,void 0,(function*(){const t=yield n.post("/auth/refresh",e,!1);return t&&(sessionStorage.setItem("token",t.token),sessionStorage.setItem("refreshToken",t.refreshToken),sessionStorage.setItem("expiration",t.expiration)),t}))}changeCompany(e){return t.__awaiter(this,void 0,void 0,(function*(){return n.post("/auth/changeCompany",e,!0)}))}register(e){return t.__awaiter(this,void 0,void 0,(function*(){return n.post("/auth/register",e,!1)}))}getCompanies(){return t.__awaiter(this,void 0,void 0,(function*(){return n.get("/auth/companies",!0)}))}getCompany(){return t.__awaiter(this,void 0,void 0,(function*(){return n.get("/auth/company",!0)}))}getRoles(){return t.__awaiter(this,void 0,void 0,(function*(){return n.get("/auth/roles",!0)}))}isAuthenticated(){return t.__awaiter(this,void 0,void 0,(function*(){try{return yield n.get("/auth/authenticated",!0)}catch(t){return!1}}))}getUser(){return t.__awaiter(this,arguments,void 0,(function*(t=null){try{return yield n.get("/auth/user",!0,t)}catch(t){throw t}}))}logout(){return t.__awaiter(this,void 0,void 0,(function*(){try{const t=yield n.post("/auth/logout",{},!0);return sessionStorage.removeItem("token"),sessionStorage.removeItem("refreshToken"),sessionStorage.removeItem("expiration"),t}catch(t){throw t}}))}getPermissions(){return t.__awaiter(this,arguments,void 0,(function*(t=null){try{return yield n.get("/auth/permissions",!0,t)}catch(t){throw t}}))}};const o=new e(r);var s=new class{getEvents(){return t.__awaiter(this,arguments,void 0,(function*(t=null){return o.get("/events",!0,t)}))}getEvent(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return o.get(`/events/${t}`,!0,e)}))}createEvent(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return o.post("/events",t,!0,e,!0)}))}updateEvent(e,r){return t.__awaiter(this,arguments,void 0,(function*(t,e,r=null){return o.put(`/events/${t}`,e,!0,r,!0)}))}deleteEvent(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return o.delete(`/events/${t}`,!0,e)}))}};const a=new e(r);var u=new class{getAllRolesWithClaims(){return t.__awaiter(this,arguments,void 0,(function*(t=null){return a.get("/roles",!0,t)}))}addRole(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return a.post("/roles",t,!0,e)}))}updateRole(e,r){return t.__awaiter(this,arguments,void 0,(function*(t,e,r=null){return a.put(`/roles/${t}`,e,!0,r)}))}deleteRole(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return a.delete(`/roles/${t}`,!0,e)}))}};const l=new e(r);var h=new class{getAllUsers(){return t.__awaiter(this,arguments,void 0,(function*(t=null){try{return yield l.get("/users",!0,t)}catch(t){throw t}}))}getUser(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){try{return yield l.get(`/users/${t}`,!0,e)}catch(t){throw t}}))}createUser(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){try{return yield l.post("/users",t,!0,e)}catch(t){throw t}}))}updateUser(e,r){return t.__awaiter(this,arguments,void 0,(function*(t,e,r=null){try{yield l.put(`/users/${t}`,e,!0,r)}catch(t){throw t}}))}updateLoggedInUser(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){try{yield l.put("/users",t,!0,e)}catch(t){throw t}}))}deleteUser(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){try{yield l.delete(`/users/${t}`,!0,e)}catch(t){throw t}}))}};const c=new e(r);var d=new class{forgotPassword(e){return t.__awaiter(this,void 0,void 0,(function*(){try{return yield c.post("/account/forgotPassword",e,!1)}catch(t){throw t}}))}resetPasswordWithToken(e){return t.__awaiter(this,void 0,void 0,(function*(){try{return yield c.post("/account/resetPasswordWithToken",e,!1)}catch(t){throw t}}))}resetPassword(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){try{return yield c.post("/account/resetPassword",t,!0,e)}catch(t){throw t}}))}};const g=new e(r);var f=new class{getMapConfig(){return t.__awaiter(this,arguments,void 0,(function*(t=null){try{return yield g.get("/mapconfig",!0,t)}catch(t){throw t}}))}updateMapConfig(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return g.put("/mapconfig",t,!0,e)}))}createMapConfig(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return g.post("/mapconfig",t,!0,e)}))}};const p=new e(r);var v=new class{getAllPermissions(){return t.__awaiter(this,arguments,void 0,(function*(t=null){return p.get("/permissions",!0,t)}))}};const w=new e(r);var _=new class{getClientAuthConfigById(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){try{return yield w.get(`/clientAuthConfig/${t}`,!0,e)}catch(t){throw t}}))}getAllClientAuthConfigs(){return t.__awaiter(this,arguments,void 0,(function*(t=null){try{return yield w.get("/clientAuthConfig",!0,t)}catch(t){throw t}}))}createClientAuthConfig(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return w.post("/clientAuthConfig",t,!0,e)}))}updateClientAuthConfig(e,r){return t.__awaiter(this,arguments,void 0,(function*(t,e,r=null){return w.put(`/clientAuthConfig/${t}`,e,!0,r)}))}deleteClientAuthConfig(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return w.delete(`/clientAuthConfig/${t}`,!0,e)}))}};const y=new e(r);var m=new class{getListings(){return t.__awaiter(this,arguments,void 0,(function*(t=null){try{return yield y.get("/listings",!0,t)}catch(t){throw t}}))}getListingDetails(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){try{return yield y.get(`/listings/${t}`,!0,e)}catch(t){throw t}}))}};const C={login:i.login,nextLogin:i.nextLogin,refreshToken:i.refreshToken,changeCompany:i.changeCompany,register:i.register,isAuthenticated:i.isAuthenticated,getCompany:i.getCompany,getCompanies:i.getCompanies,getRoles:i.getRoles,getPermissions:i.getPermissions,logout:i.logout,getUser:i.getUser},A={getAll:s.getEvents,get:s.getEvent,create:s.createEvent,update:s.updateEvent,delete:s.deleteEvent},T={get:u.getAllRolesWithClaims,create:u.addRole,update:u.updateRole,delete:u.deleteRole},$=h,P=m,k={resetPassword:d.resetPassword,resetPasswordWithToken:d.resetPasswordWithToken,forgotPassword:d.forgotPassword},x={get:f.getMapConfig,update:f.updateMapConfig,create:f.createMapConfig},E={get:_.getClientAuthConfigById,getAll:_.getAllClientAuthConfigs,update:_.updateClientAuthConfig,create:_.createClientAuthConfig,delete:_.deleteClientAuthConfig},W={get:v.getAllPermissions},U={auth:C,events:A,roles:T,users:$,account:k,mapConfig:x,permissions:W,clientAuthConfig:E,listings:P};exports.account=k,exports.auth=C,exports.clientAuthConfig=E,exports.default=U,exports.events=A,exports.listings=P,exports.mapConfig=x,exports.permissions=W,exports.roles=T,exports.users=$;
2
2
  //# sourceMappingURL=index.cjs.js.map
package/dist/index.d.ts CHANGED
@@ -6,7 +6,7 @@ import Role from "./types/role";
6
6
  import Company from "./types/company";
7
7
  import HireControlConfig from "./types/hireControlConfig";
8
8
  import ClientAuthConfig from "./types/clientAuthConfig";
9
- import Event from "./types/event";
9
+ import Event, { EventDates, EventDateType, EventInstance } from "./types/event";
10
10
  import { Listing } from "./types/listing";
11
11
  export declare const auth: {
12
12
  login: (clientLogInRequest: import("./types/clientLoginRequest").default) => Promise<any>;
@@ -57,7 +57,7 @@ export declare const clientAuthConfig: {
57
57
  export declare const permissions: {
58
58
  get: (authToken?: string | null) => Promise<string[]>;
59
59
  };
60
- export type { Register, User, Company, Role, HireControlConfig, ClientAuthConfig, Event, Listing, };
60
+ export type { Register, User, Company, Role, HireControlConfig, ClientAuthConfig, Event, Listing, EventDates, EventDateType, EventInstance, };
61
61
  declare const hcApi: {
62
62
  auth: {
63
63
  login: (clientLogInRequest: import("./types/clientLoginRequest").default) => Promise<any>;
@@ -1,33 +1,47 @@
1
- interface Event {
1
+ type Event = {
2
2
  id?: string;
3
3
  title?: string;
4
4
  subtitle?: string;
5
5
  description?: string;
6
6
  shortDescription?: string;
7
7
  richDescription?: string;
8
+ richDescriptionJson?: any;
8
9
  location?: {
10
+ subtitle?: string;
11
+ name?: string;
9
12
  address?: string;
10
- city?: string;
11
- state?: string;
12
- country?: string;
13
- postalCode?: string;
14
13
  coordinates?: {
15
14
  latitude?: number;
16
15
  longitude?: number;
17
16
  };
18
17
  };
19
18
  format?: string[];
20
- dates?: {
21
- startDateTime?: string;
22
- endDateTime?: string;
23
- timezone?: string;
24
- }[];
19
+ eventDates: EventDates;
25
20
  emailToFormSubmission?: string[];
26
- images?: string[];
21
+ image: any;
22
+ imageUrl: string;
23
+ imageFocalPoint: {
24
+ x: number;
25
+ y: number;
26
+ };
27
27
  websiteUrl?: string;
28
+ registrationType?: "none" | "link" | "hirecontrol";
28
29
  registrationUrl?: string;
29
30
  markupContent?: string;
30
31
  companyId?: string;
31
32
  filters?: any;
32
- }
33
+ };
34
+ export type EventDates = {
35
+ type: EventDateType;
36
+ startDate: string;
37
+ endDate: string;
38
+ publishStartDate: string;
39
+ publishEndDate: string;
40
+ instances?: EventInstance[];
41
+ };
42
+ export type EventDateType = "singular" | "multiple";
43
+ export type EventInstance = {
44
+ startDateTime: string;
45
+ endDateTime: string;
46
+ };
33
47
  export default Event;
@@ -6,57 +6,123 @@ class FetchHandler {
6
6
  }
7
7
 
8
8
  // GET request with/without auth
9
- public async get<T>(endpoint: string, auth: boolean = false, authToken: string | null = null): Promise<T> {
9
+ public async get<T>(
10
+ endpoint: string,
11
+ auth: boolean = false,
12
+ authToken: string | null = null
13
+ ): Promise<T> {
10
14
  const options: RequestInit = {
11
- method: 'GET',
12
- credentials: 'include', // Include credentials (cookies) in the request
15
+ method: "GET",
16
+ credentials: "include", // Include credentials (cookies) in the request
13
17
  };
14
- return auth ? this.fetchWithAuth<T>(endpoint, options, authToken) : this.fetchWithoutAuth<T>(endpoint, options);
18
+ return auth
19
+ ? this.fetchWithAuth<T>(endpoint, options, authToken)
20
+ : this.fetchWithoutAuth<T>(endpoint, options);
15
21
  }
16
22
 
17
- // POST request with/without auth
18
- public async post<T, R>(endpoint: string, body: T, auth: boolean = false, authToken: string | null = null): Promise<R> {
23
+ // POST request with/without auth, with optional formData conversion
24
+ public async post<T, R>(
25
+ endpoint: string,
26
+ body: T,
27
+ auth: boolean = false,
28
+ authToken: string | null = null,
29
+ formData: boolean = false
30
+ ): Promise<R> {
19
31
  const options: RequestInit = {
20
- method: 'POST',
21
- headers: {
22
- 'Content-Type': 'application/json',
23
- },
24
- body: JSON.stringify(body),
25
- credentials: 'include',
32
+ method: "POST",
33
+ credentials: "include",
26
34
  };
27
- return auth ? this.fetchWithAuth<R>(endpoint, options, authToken) : this.fetchWithoutAuth<R>(endpoint, options);
35
+ if (formData) {
36
+ options.body = this.convertToFormData(body);
37
+ } else {
38
+ options.headers = { "Content-Type": "application/json" };
39
+ options.body = JSON.stringify(body);
40
+ }
41
+ return auth
42
+ ? this.fetchWithAuth<R>(endpoint, options, authToken)
43
+ : this.fetchWithoutAuth<R>(endpoint, options);
28
44
  }
29
45
 
30
- // PUT request with/without auth
31
- public async put<T, R>(endpoint: string, body: T, auth: boolean = false, authToken: string | null = null): Promise<R> {
46
+ // PUT request with/without auth, with optional formData conversion
47
+ public async put<T, R>(
48
+ endpoint: string,
49
+ body: T,
50
+ auth: boolean = false,
51
+ authToken: string | null = null,
52
+ formData: boolean = false
53
+ ): Promise<R> {
32
54
  const options: RequestInit = {
33
- method: 'PUT',
34
- headers: {
35
- 'Content-Type': 'application/json',
36
- },
37
- body: JSON.stringify(body),
38
- credentials: 'include',
55
+ method: "PUT",
56
+ credentials: "include",
39
57
  };
40
- return auth ? this.fetchWithAuth<R>(endpoint, options, authToken) : this.fetchWithoutAuth<R>(endpoint, options);
58
+ if (formData) {
59
+ options.body = this.convertToFormData(body);
60
+ } else {
61
+ options.headers = { "Content-Type": "application/json" };
62
+ options.body = JSON.stringify(body);
63
+ }
64
+ return auth
65
+ ? this.fetchWithAuth<R>(endpoint, options, authToken)
66
+ : this.fetchWithoutAuth<R>(endpoint, options);
41
67
  }
42
68
 
43
69
  // DELETE request with/without auth
44
- public async delete<T>(endpoint: string, auth: boolean = false, authToken: string | null = null): Promise<T> {
70
+ public async delete<T>(
71
+ endpoint: string,
72
+ auth: boolean = false,
73
+ authToken: string | null = null
74
+ ): Promise<T> {
45
75
  const options: RequestInit = {
46
- method: 'DELETE',
47
- credentials: 'include',
76
+ method: "DELETE",
77
+ credentials: "include",
48
78
  };
49
- return auth ? this.fetchWithAuth<T>(endpoint, options, authToken) : this.fetchWithoutAuth<T>(endpoint, options);
79
+ return auth
80
+ ? this.fetchWithAuth<T>(endpoint, options, authToken)
81
+ : this.fetchWithoutAuth<T>(endpoint, options);
82
+ }
83
+
84
+ // Convert object to FormData recursively
85
+ private convertToFormData(
86
+ body: any,
87
+ formData: FormData = new FormData(),
88
+ parentKey: string = ""
89
+ ): FormData {
90
+ if (
91
+ body instanceof File ||
92
+ typeof body === "string" ||
93
+ typeof body === "number" ||
94
+ typeof body === "boolean"
95
+ ) {
96
+ formData.append(parentKey, body as any);
97
+ } else if (body instanceof Array) {
98
+ body.forEach((item, index) => {
99
+ this.convertToFormData(item, formData, `${parentKey}[${index}]`);
100
+ });
101
+ } else if (body instanceof Object) {
102
+ Object.keys(body).forEach((key) => {
103
+ const value = body[key];
104
+ const newKey = parentKey ? `${parentKey}[${key}]` : key;
105
+ this.convertToFormData(value, formData, newKey);
106
+ });
107
+ }
108
+ return formData;
50
109
  }
51
110
 
52
111
  // Fetch without auth (still sending cookies for non-authenticated endpoints if needed)
53
- private async fetchWithoutAuth<T>(endpoint: string, options: RequestInit): Promise<T> {
112
+ private async fetchWithoutAuth<T>(
113
+ endpoint: string,
114
+ options: RequestInit
115
+ ): Promise<T> {
54
116
  const response = await fetch(`${this.apiUrl}${endpoint}`, options);
55
117
  return this.handleResponse<T>(response);
56
118
  }
57
119
 
58
120
  // Fetch with auth, optionally including a Bearer token
59
- private async fetchWithAuth<T>(endpoint: string, options: RequestInit, authToken: string | null): Promise<T> {
121
+ private async fetchWithAuth<T>(
122
+ endpoint: string,
123
+ options: RequestInit,
124
+ authToken: string | null
125
+ ): Promise<T> {
60
126
  if (authToken) {
61
127
  options.headers = {
62
128
  ...options.headers,
@@ -78,43 +144,42 @@ class FetchHandler {
78
144
  return this.handleResponse<T>(response);
79
145
  }
80
146
 
81
- private async handleResponse<T>(response: Response): Promise<T> {
82
- if (!response.ok || !response.status.toString().startsWith("2")) {
83
- let errorMessage = `Error: ${response.status} ${response.statusText}`;
84
-
85
- try {
86
- const errorData = await response.json();
87
- console.log(errorData);
88
- if (errorData && errorData.message) {
89
- errorMessage = errorData.message;
147
+ private async handleResponse<T>(response: Response): Promise<T> {
148
+ if (!response.ok || !response.status.toString().startsWith("2")) {
149
+ let errorMessage = `Error: ${response.status} ${response.statusText}`;
150
+ try {
151
+ const errorData = await response.json();
152
+ console.log(errorData);
153
+ if (errorData && errorData.message) {
154
+ errorMessage = errorData.message;
155
+ }
156
+ } catch (error) {
157
+ console.error("Failed to parse error response:", error);
90
158
  }
91
- } catch (error) {
92
- console.error("Failed to parse error response:", error);
159
+ throw {
160
+ statusCode: response.status,
161
+ errorMessage,
162
+ };
93
163
  }
94
- throw {
95
- statusCode: response.status,
96
- errorMessage,
97
- };
164
+ return response.status === 200 ? response.json() : null;
98
165
  }
99
- return response.status == 200 ? response.json() : null;
100
- }
101
166
 
102
- private async refreshToken(): Promise<boolean> {
103
- const refreshResponse = await fetch(`${this.apiUrl}/auth/refresh`, {
104
- method: 'POST',
105
- headers: {
106
- 'Content-Type': 'application/json',
107
- },
108
- credentials: 'include',
109
- });
167
+ private async refreshToken(): Promise<boolean> {
168
+ const refreshResponse = await fetch(`${this.apiUrl}/auth/refresh`, {
169
+ method: "POST",
170
+ headers: {
171
+ "Content-Type": "application/json",
172
+ },
173
+ credentials: "include",
174
+ });
110
175
 
111
- if (refreshResponse.ok) {
112
- return true;
113
- } else {
114
- console.error("Failed to refresh token");
115
- return false;
176
+ if (refreshResponse.ok) {
177
+ return true;
178
+ } else {
179
+ console.error("Failed to refresh token");
180
+ return false;
181
+ }
116
182
  }
117
183
  }
118
- }
119
184
 
120
185
  export default FetchHandler;
package/index.ts CHANGED
@@ -17,7 +17,7 @@ import Role from "./types/role";
17
17
  import Company from "./types/company";
18
18
  import HireControlConfig from "./types/hireControlConfig";
19
19
  import ClientAuthConfig from "./types/clientAuthConfig";
20
- import Event from "./types/event";
20
+ import Event, { EventDates, EventDateType, EventInstance } from "./types/event";
21
21
  import { Listing } from "./types/listing";
22
22
 
23
23
  export const auth = {
@@ -87,6 +87,9 @@ export type {
87
87
  ClientAuthConfig,
88
88
  Event,
89
89
  Listing,
90
+ EventDates,
91
+ EventDateType,
92
+ EventInstance,
90
93
  };
91
94
 
92
95
  const hcApi = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abcagency/hire-control-sdk",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "main": "dist/index.cjs.js",
5
5
  "module": "dist/index.esm.js",
6
6
  "types": "dist/index.d.ts",
package/types/event.ts CHANGED
@@ -1,30 +1,51 @@
1
- interface Event {
1
+ type Event = {
2
2
  id?: string;
3
3
  title?: string;
4
4
  subtitle?: string;
5
5
  description?: string;
6
6
  shortDescription?: string;
7
7
  richDescription?: string;
8
+ richDescriptionJson?: any;
8
9
  location?: {
10
+ subtitle?: string;
11
+ name?: string;
9
12
  address?: string;
10
- city?: string;
11
- state?: string;
12
- country?: string;
13
- postalCode?: string;
14
13
  coordinates?: {
15
14
  latitude?: number;
16
15
  longitude?: number;
17
16
  };
18
17
  };
19
18
  format?: string[];
20
- dates?: { startDateTime?: string; endDateTime?: string; timezone?: string }[];
19
+ eventDates: EventDates;
21
20
  emailToFormSubmission?: string[];
22
- images?: string[];
21
+ image: any;
22
+ imageUrl: string;
23
+ imageFocalPoint: {
24
+ x: number;
25
+ y: number;
26
+ };
23
27
  websiteUrl?: string;
24
- registrationUrl?: string;
28
+ registrationType?: "none" | "link" | "hirecontrol"; // Added registrationType here
29
+ registrationUrl?: string; // Optional, for "link" type
25
30
  markupContent?: string;
26
31
  companyId?: string;
27
32
  filters?: any;
28
- }
33
+ };
34
+
35
+ export type EventDates = {
36
+ type: EventDateType;
37
+ startDate: string;
38
+ endDate: string;
39
+ publishStartDate: string;
40
+ publishEndDate: string;
41
+ instances?: EventInstance[];
42
+ };
43
+
44
+ export type EventDateType = "singular" | "multiple";
45
+
46
+ export type EventInstance = {
47
+ startDateTime: string;
48
+ endDateTime: string;
49
+ };
29
50
 
30
51
  export default Event;