@abcagency/hire-control-sdk 1.0.26 → 1.0.28

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.
@@ -0,0 +1,120 @@
1
+ import FetchHandler from "../handlers/fetchHandler";
2
+ import { API_URL } from "../constants/config";
3
+ import FormSubmission, { FormSubmissionStatus } from "../types/formSubmission";
4
+ import ResultsWrapper from "../types/resultsWrapper";
5
+
6
+ const fetchHandler = new FetchHandler(API_URL);
7
+
8
+ class FormSubmissionsController {
9
+ /**
10
+ * Submit a new form via a POST request.
11
+ * @param {FormSubmission} formSubmission - The form submission data.
12
+ * @param {string | null} authToken - Optional authentication token.
13
+ * @returns {Promise<string>} - Success message.
14
+ */
15
+ async submitFormSubmission(
16
+ formSubmission: FormSubmission,
17
+ authToken: string | null = null
18
+ ): Promise<string> {
19
+ return fetchHandler.post<FormSubmission, string>(
20
+ "/formsubmission",
21
+ formSubmission,
22
+ true,
23
+ authToken
24
+ );
25
+ }
26
+
27
+ /**
28
+ * Get form submissions with optional filters.
29
+ * @param {number} pageSize - Number of results per page (default: 20).
30
+ * @param {number} pageNumber - Page number (default: 1).
31
+ * @param {string | null} type - Optional type filter.
32
+ * @param {Date | null} from - Optional start date filter.
33
+ * @param {Date | null} to - Optional end date filter.
34
+ * @param {string | null} authToken - Optional authentication token.
35
+ * @returns {Promise<ResultsWrapper<FormSubmission>>} - A list of form submissions.
36
+ */
37
+ async getFormSubmissions(
38
+ pageSize: number = 20,
39
+ pageNumber: number = 1,
40
+ type: string | null = null,
41
+ status: FormSubmissionStatus | null = null,
42
+ from: Date | null = null,
43
+ to: Date | null = null,
44
+ authToken: string | null = null
45
+ ): Promise<ResultsWrapper<FormSubmission>> {
46
+ const params = new URLSearchParams({
47
+ pageSize: pageSize.toString(),
48
+ pageNumber: pageNumber.toString(),
49
+ });
50
+ if (status) params.append("status", status.toString());
51
+ if (type) params.append("type", type);
52
+ if (from) params.append("from", from.toISOString());
53
+ if (to) params.append("to", to.toISOString());
54
+
55
+ return fetchHandler.get<ResultsWrapper<FormSubmission>>(
56
+ `/formsubmission?${params.toString()}`,
57
+ true,
58
+ authToken
59
+ );
60
+ }
61
+
62
+ /**
63
+ * Export form submissions as a CSV file.
64
+ * @param {number} pageSize - Number of results per page (default: 20).
65
+ * @param {number} pageNumber - Page number (default: 1).
66
+ * @param {string | null} type - Optional type filter.
67
+ * @param {FormSubmissionStatus | null} status - Optional status filter.
68
+ * @param {Date | null} from - Optional start date filter.
69
+ * @param {Date | null} to - Optional end date filter.
70
+ * @param {string | null} authToken - Optional authentication token.
71
+ * @returns {Promise<void>} - Triggers a CSV file download.
72
+ */
73
+ async exportFormSubmissionsCsv(
74
+ pageSize: number = 20,
75
+ pageNumber: number = 1,
76
+ type: string | null = null,
77
+ status: FormSubmissionStatus | null = null,
78
+ from: Date | null = null,
79
+ to: Date | null = null,
80
+ authToken: string | null = null
81
+ ): Promise<void> {
82
+ const params = new URLSearchParams({
83
+ pageSize: pageSize.toString(),
84
+ pageNumber: pageNumber.toString(),
85
+ });
86
+ if (status) params.append("status", status.toString());
87
+ if (type) params.append("type", type);
88
+ if (from) params.append("from", from.toISOString());
89
+ if (to) params.append("to", to.toISOString());
90
+
91
+ const response = await fetchHandler.getFile(
92
+ `/formsubmission/export-csv?${params.toString()}`,
93
+ true,
94
+ authToken
95
+ );
96
+
97
+ // Create a download link
98
+ const url = window.URL.createObjectURL(response);
99
+ const a = document.createElement("a");
100
+ a.href = url;
101
+ a.download = "form_submissions.csv";
102
+ document.body.appendChild(a);
103
+ a.click();
104
+ window.URL.revokeObjectURL(url);
105
+ document.body.removeChild(a);
106
+ }
107
+
108
+ /**
109
+ * Get a list of distinct form submission types for the authenticated company.
110
+ * @param {string | null} authToken - Optional authentication token.
111
+ * @returns {Promise<string[]>} - A list of unique form submission types.
112
+ */
113
+ async getFormSubmissionTypes(
114
+ authToken: string | null = null
115
+ ): Promise<string[]> {
116
+ return fetchHandler.get<string[]>("/formsubmission/types", true, authToken);
117
+ }
118
+ }
119
+
120
+ export default new FormSubmissionsController();
@@ -0,0 +1,42 @@
1
+ import FormSubmission, { FormSubmissionStatus } from "../types/formSubmission";
2
+ import ResultsWrapper from "../types/resultsWrapper";
3
+ declare class FormSubmissionsController {
4
+ /**
5
+ * Submit a new form via a POST request.
6
+ * @param {FormSubmission} formSubmission - The form submission data.
7
+ * @param {string | null} authToken - Optional authentication token.
8
+ * @returns {Promise<string>} - Success message.
9
+ */
10
+ submitFormSubmission(formSubmission: FormSubmission, authToken?: string | null): Promise<string>;
11
+ /**
12
+ * Get form submissions with optional filters.
13
+ * @param {number} pageSize - Number of results per page (default: 20).
14
+ * @param {number} pageNumber - Page number (default: 1).
15
+ * @param {string | null} type - Optional type filter.
16
+ * @param {Date | null} from - Optional start date filter.
17
+ * @param {Date | null} to - Optional end date filter.
18
+ * @param {string | null} authToken - Optional authentication token.
19
+ * @returns {Promise<ResultsWrapper<FormSubmission>>} - A list of form submissions.
20
+ */
21
+ getFormSubmissions(pageSize?: number, pageNumber?: number, type?: string | null, status?: FormSubmissionStatus | null, from?: Date | null, to?: Date | null, authToken?: string | null): Promise<ResultsWrapper<FormSubmission>>;
22
+ /**
23
+ * Export form submissions as a CSV file.
24
+ * @param {number} pageSize - Number of results per page (default: 20).
25
+ * @param {number} pageNumber - Page number (default: 1).
26
+ * @param {string | null} type - Optional type filter.
27
+ * @param {FormSubmissionStatus | null} status - Optional status filter.
28
+ * @param {Date | null} from - Optional start date filter.
29
+ * @param {Date | null} to - Optional end date filter.
30
+ * @param {string | null} authToken - Optional authentication token.
31
+ * @returns {Promise<void>} - Triggers a CSV file download.
32
+ */
33
+ exportFormSubmissionsCsv(pageSize?: number, pageNumber?: number, type?: string | null, status?: FormSubmissionStatus | null, from?: Date | null, to?: Date | null, authToken?: string | null): Promise<void>;
34
+ /**
35
+ * Get a list of distinct form submission types for the authenticated company.
36
+ * @param {string | null} authToken - Optional authentication token.
37
+ * @returns {Promise<string[]>} - A list of unique form submission types.
38
+ */
39
+ getFormSubmissionTypes(authToken?: string | null): Promise<string[]>;
40
+ }
41
+ declare const _default: FormSubmissionsController;
42
+ export default _default;
@@ -5,6 +5,7 @@ declare class FetchHandler {
5
5
  post<T, R>(endpoint: string, body: T, auth?: boolean, authToken?: string | null, formData?: boolean): Promise<R>;
6
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
+ getFile(endpoint: string, auth?: boolean, authToken?: string | null): Promise<Blob>;
8
9
  private convertToFormData;
9
10
  private fetchWithoutAuth;
10
11
  private fetchWithAuth;
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,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{statusCode:t.status};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)}))}getEventBySlug(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return o.get(`/events/details/${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 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 d=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 h=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 p=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 f=new e(r);var _=new class{getAllPermissions(){return t.__awaiter(this,arguments,void 0,(function*(t=null){return f.get("/permissions",!0,t)}))}};const v=new e(r);var w=new class{getClientAuthConfigById(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){try{return yield v.get(`/clientAuthConfig/${t}`,!0,e)}catch(t){throw t}}))}getAllClientAuthConfigs(){return t.__awaiter(this,arguments,void 0,(function*(t=null){try{return yield v.get("/clientAuthConfig",!0,t)}catch(t){throw t}}))}createClientAuthConfig(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return v.post("/clientAuthConfig",t,!0,e)}))}updateClientAuthConfig(e,r){return t.__awaiter(this,arguments,void 0,(function*(t,e,r=null){return v.put(`/clientAuthConfig/${t}`,e,!0,r)}))}deleteClientAuthConfig(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return v.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=new e(r);var A=new class{uploadMedia(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return C.post("/media/upload",t,!0,e,!0)}))}listMedia(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){const r=new URLSearchParams({folderKey:t});return C.get(`/media/list?${r.toString()}`,!0,e)}))}deleteMedia(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){const r=new URLSearchParams({key:t});return C.delete(`/media/delete?${r.toString()}`,!0,e)}))}};const $=new e(r);var T=new class{getFilters(){return t.__awaiter(this,arguments,void 0,(function*(t=null){return $.get("/filters",!0,t)}))}getFilter(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return $.get(`/filters/${t}`,!0,e)}))}createFilter(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return $.post("/filters",t,!0,e)}))}updateFilter(e,r){return t.__awaiter(this,arguments,void 0,(function*(t,e,r=null){return $.put(`/filters/${t}`,e,!0,r)}))}deleteFilter(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return $.delete(`/filters/${t}`,!0,e)}))}};const L=new e(r);var x=new class{getAppendListings(){return t.__awaiter(this,arguments,void 0,(function*(t=null){return L.get("/appendListings",!0,t)}))}getAppendListing(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return L.get(`/appendListings/${t}`,!0,e)}))}createAppendListing(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return L.post("/appendListings",t,!0,e)}))}updateAppendListing(e,r){return t.__awaiter(this,arguments,void 0,(function*(t,e,r=null){return L.put(`/appendListings/${t}`,e,!0,r)}))}deleteAppendListing(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return L.delete(`/appendListings/${t}`,!0,e)}))}};const P=new e(r);var F,k,E=new class{getForms(){return t.__awaiter(this,arguments,void 0,(function*(t=null){return P.get("/forms",!0,t)}))}getForm(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return P.get(`/forms/${t}`,!0,e)}))}createForm(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return P.post("/forms",t,!0,e)}))}updateForm(e,r){return t.__awaiter(this,arguments,void 0,(function*(t,e,r=null){return P.put(`/forms/${t}`,e,!0,r)}))}deleteForm(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return P.delete(`/forms/${t}`,!0,e)}))}};exports.EventType=void 0,(F=exports.EventType||(exports.EventType={}))[F.Virtual=0]="Virtual",F[F.InPerson=1]="InPerson",F[F.Hybrid=2]="Hybrid",exports.CallToActionType=void 0,(k=exports.CallToActionType||(exports.CallToActionType={}))[k.Button=0]="Button",k[k.Link=1]="Link",k[k.Download=2]="Download",k[k.HireControlRegistration=3]="HireControlRegistration";const R={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},S={getAll:s.getEvents,get:s.getEvent,getBySlug:s.getEventBySlug,create:s.createEvent,update:s.updateEvent,delete:s.deleteEvent},U={get:u.getAllRolesWithClaims,create:u.addRole,update:u.updateRole,delete:u.deleteRole},W=d,b=m,M={resetPassword:h.resetPassword,resetPasswordWithToken:h.resetPasswordWithToken,forgotPassword:h.forgotPassword},I={get:p.getMapConfig,update:p.updateMapConfig,create:p.createMapConfig},j={get:w.getClientAuthConfigById,getAll:w.getAllClientAuthConfigs,update:w.updateClientAuthConfig,create:w.createClientAuthConfig,delete:w.deleteClientAuthConfig},D={upload:A.uploadMedia,get:A.listMedia,delete:A.deleteMedia},O={getList:T.getFilters,get:T.getFilter,update:T.updateFilter,create:T.createFilter,delete:T.deleteFilter},B={get:x.getAppendListings,getAppendListing:x.getAppendListing,create:x.createAppendListing,update:x.updateAppendListing,delete:x.deleteAppendListing},H={get:_.getAllPermissions},J=E,N={auth:R,events:S,roles:U,users:W,account:M,mapConfig:I,permissions:H,clientAuthConfig:j,filters:O,listings:b,media:D,appendListings:B,forms:J};exports.account=M,exports.appendListings=B,exports.auth=R,exports.clientAuthConfig=j,exports.default=N,exports.events=S,exports.filters=O,exports.forms=J,exports.listings=b,exports.mapConfig=I,exports.media=D,exports.permissions=H,exports.roles=U,exports.users=W;
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,n=null){const r={method:"GET",credentials:"include"};return e?this.fetchWithAuth(t,r,n):this.fetchWithoutAuth(t,r)}))}post(e,n){return t.__awaiter(this,arguments,void 0,(function*(t,e,n=!1,r=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)),n?this.fetchWithAuth(t,o,r):this.fetchWithoutAuth(t,o)}))}put(e,n){return t.__awaiter(this,arguments,void 0,(function*(t,e,n=!1,r=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)),n?this.fetchWithAuth(t,o,r):this.fetchWithoutAuth(t,o)}))}delete(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=!1,n=null){const r={method:"DELETE",credentials:"include"};return e?this.fetchWithAuth(t,r,n):this.fetchWithoutAuth(t,r)}))}getFile(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=!1,n=null){const r={method:"GET",credentials:"include",headers:e&&n?{Authorization:`Bearer ${n}`}:{}},i=yield fetch(`${this.apiUrl}${t}`,r);if(!i.ok)throw new Error(`Failed to fetch file: ${i.statusText}`);return i.blob()}))}convertToFormData(t,e=new FormData,n=""){return t instanceof File||"string"==typeof t||"number"==typeof t||"boolean"==typeof t?e.append(n,t):t instanceof Array?t.forEach(((t,r)=>{this.convertToFormData(t,e,`${n}[${r}]`)})):t instanceof Object&&Object.keys(t).forEach((r=>{const i=t[r],o=n?`${n}[${r}]`:r;this.convertToFormData(i,e,o)})),e}fetchWithoutAuth(e,n){return t.__awaiter(this,void 0,void 0,(function*(){const t=yield fetch(`${this.apiUrl}${e}`,n);return this.handleResponse(t)}))}fetchWithAuth(e,n,r){return t.__awaiter(this,void 0,void 0,(function*(){r&&(n.headers=Object.assign(Object.assign({},n.headers),{Authorization:`Bearer ${r}`}));let t=yield fetch(`${this.apiUrl}${e}`,n);if(401===t.status){if(!(yield this.refreshToken()))throw{statusCode:t.status};t=yield fetch(`${this.apiUrl}${e}`,n)}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 n=yield e.json();console.log(n),n&&n.message&&(t=n.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 n="https://api.myhirecontrol.com",r=new e(n);var i=new class{login(e){return t.__awaiter(this,void 0,void 0,(function*(){return r.post("/auth/login",e,!1)}))}nextLogin(e){return t.__awaiter(this,void 0,void 0,(function*(){return yield r.post("/auth/nextLogin",e,!1)}))}refreshToken(e){return t.__awaiter(this,void 0,void 0,(function*(){const t=yield r.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 r.post("/auth/changeCompany",e,!0)}))}register(e){return t.__awaiter(this,void 0,void 0,(function*(){return r.post("/auth/register",e,!1)}))}getCompanies(){return t.__awaiter(this,void 0,void 0,(function*(){return r.get("/auth/companies",!0)}))}getCompany(){return t.__awaiter(this,void 0,void 0,(function*(){return r.get("/auth/company",!0)}))}getRoles(){return t.__awaiter(this,void 0,void 0,(function*(){return r.get("/auth/roles",!0)}))}isAuthenticated(){return t.__awaiter(this,void 0,void 0,(function*(){try{return yield r.get("/auth/authenticated",!0)}catch(t){return!1}}))}getUser(){return t.__awaiter(this,arguments,void 0,(function*(t=null){try{return yield r.get("/auth/user",!0,t)}catch(t){throw t}}))}logout(){return t.__awaiter(this,void 0,void 0,(function*(){try{const t=yield r.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 r.get("/auth/permissions",!0,t)}catch(t){throw t}}))}};const o=new e(n);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)}))}getEventBySlug(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return o.get(`/events/details/${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,n){return t.__awaiter(this,arguments,void 0,(function*(t,e,n=null){return o.put(`/events/${t}`,e,!0,n)}))}deleteEvent(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return o.delete(`/events/${t}`,!0,e)}))}};const a=new e(n);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,n){return t.__awaiter(this,arguments,void 0,(function*(t,e,n=null){return a.put(`/roles/${t}`,e,!0,n)}))}deleteRole(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return a.delete(`/roles/${t}`,!0,e)}))}};const l=new e(n);var d=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,n){return t.__awaiter(this,arguments,void 0,(function*(t,e,n=null){try{yield l.put(`/users/${t}`,e,!0,n)}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(n);var h=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 p=new e(n);var g=new class{getMapConfig(){return t.__awaiter(this,arguments,void 0,(function*(t=null){try{return yield p.get("/mapconfig",!0,t)}catch(t){throw t}}))}updateMapConfig(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return p.put("/mapconfig",t,!0,e)}))}createMapConfig(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return p.post("/mapconfig",t,!0,e)}))}};const f=new e(n);var _=new class{getAllPermissions(){return t.__awaiter(this,arguments,void 0,(function*(t=null){return f.get("/permissions",!0,t)}))}};const w=new e(n);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,n){return t.__awaiter(this,arguments,void 0,(function*(t,e,n=null){return w.put(`/clientAuthConfig/${t}`,e,!0,n)}))}deleteClientAuthConfig(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return w.delete(`/clientAuthConfig/${t}`,!0,e)}))}};const m=new e(n);var y=new class{getListings(){return t.__awaiter(this,arguments,void 0,(function*(t=null){try{return yield m.get("/listings",!0,t)}catch(t){throw t}}))}getListingDetails(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){try{return yield m.get(`/listings/${t}`,!0,e)}catch(t){throw t}}))}};const C=new e(n);var A=new class{uploadMedia(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return C.post("/media/upload",t,!0,e,!0)}))}listMedia(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){const n=new URLSearchParams({folderKey:t});return C.get(`/media/list?${n.toString()}`,!0,e)}))}deleteMedia(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){const n=new URLSearchParams({key:t});return C.delete(`/media/delete?${n.toString()}`,!0,e)}))}};const S=new e(n);var $=new class{getFilters(){return t.__awaiter(this,arguments,void 0,(function*(t=null){return S.get("/filters",!0,t)}))}getFilter(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return S.get(`/filters/${t}`,!0,e)}))}createFilter(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return S.post("/filters",t,!0,e)}))}updateFilter(e,n){return t.__awaiter(this,arguments,void 0,(function*(t,e,n=null){return S.put(`/filters/${t}`,e,!0,n)}))}deleteFilter(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return S.delete(`/filters/${t}`,!0,e)}))}};const b=new e(n);var T=new class{getAppendListings(){return t.__awaiter(this,arguments,void 0,(function*(t=null){return b.get("/appendListings",!0,t)}))}getAppendListing(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return b.get(`/appendListings/${t}`,!0,e)}))}createAppendListing(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return b.post("/appendListings",t,!0,e)}))}updateAppendListing(e,n){return t.__awaiter(this,arguments,void 0,(function*(t,e,n=null){return b.put(`/appendListings/${t}`,e,!0,n)}))}deleteAppendListing(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return b.delete(`/appendListings/${t}`,!0,e)}))}};const L=new e(n);var x=new class{getForms(){return t.__awaiter(this,arguments,void 0,(function*(t=null){return L.get("/forms",!0,t)}))}getForm(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return L.get(`/forms/${t}`,!0,e)}))}createForm(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return L.post("/forms",t,!0,e)}))}updateForm(e,n){return t.__awaiter(this,arguments,void 0,(function*(t,e,n=null){return L.put(`/forms/${t}`,e,!0,n)}))}deleteForm(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return L.delete(`/forms/${t}`,!0,e)}))}};const F=new e(n);var P,R,k,E=new class{submitFormSubmission(e){return t.__awaiter(this,arguments,void 0,(function*(t,e=null){return F.post("/formsubmission",t,!0,e)}))}getFormSubmissions(){return t.__awaiter(this,arguments,void 0,(function*(t=20,e=1,n=null,r=null,i=null,o=null,s=null){const a=new URLSearchParams({pageSize:t.toString(),pageNumber:e.toString()});return r&&a.append("status",r.toString()),n&&a.append("type",n),i&&a.append("from",i.toISOString()),o&&a.append("to",o.toISOString()),F.get(`/formsubmission?${a.toString()}`,!0,s)}))}exportFormSubmissionsCsv(){return t.__awaiter(this,arguments,void 0,(function*(t=20,e=1,n=null,r=null,i=null,o=null,s=null){const a=new URLSearchParams({pageSize:t.toString(),pageNumber:e.toString()});r&&a.append("status",r.toString()),n&&a.append("type",n),i&&a.append("from",i.toISOString()),o&&a.append("to",o.toISOString());const u=yield F.getFile(`/formsubmission/export-csv?${a.toString()}`,!0,s),l=window.URL.createObjectURL(u),d=document.createElement("a");d.href=l,d.download="form_submissions.csv",document.body.appendChild(d),d.click(),window.URL.revokeObjectURL(l),document.body.removeChild(d)}))}getFormSubmissionTypes(){return t.__awaiter(this,arguments,void 0,(function*(t=null){return F.get("/formsubmission/types",!0,t)}))}};exports.EventType=void 0,(P=exports.EventType||(exports.EventType={}))[P.Virtual=0]="Virtual",P[P.InPerson=1]="InPerson",P[P.Hybrid=2]="Hybrid",exports.CallToActionType=void 0,(R=exports.CallToActionType||(exports.CallToActionType={}))[R.Button=0]="Button",R[R.Link=1]="Link",R[R.Download=2]="Download",R[R.HireControlRegistration=3]="HireControlRegistration",exports.FormSubmissionStatus=void 0,(k=exports.FormSubmissionStatus||(exports.FormSubmissionStatus={}))[k.Submitted=1]="Submitted",k[k.Hold=2]="Hold",k[k.Rejected=3]="Rejected",k[k.Sent=4]="Sent";const U={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},W={getAll:s.getEvents,get:s.getEvent,getBySlug:s.getEventBySlug,create:s.createEvent,update:s.updateEvent,delete:s.deleteEvent},I={get:u.getAllRolesWithClaims,create:u.addRole,update:u.updateRole,delete:u.deleteRole},O=d,j=y,M={resetPassword:h.resetPassword,resetPasswordWithToken:h.resetPasswordWithToken,forgotPassword:h.forgotPassword},D={get:g.getMapConfig,update:g.updateMapConfig,create:g.createMapConfig},B={get:v.getClientAuthConfigById,getAll:v.getAllClientAuthConfigs,update:v.updateClientAuthConfig,create:v.createClientAuthConfig,delete:v.deleteClientAuthConfig},H={upload:A.uploadMedia,get:A.listMedia,delete:A.deleteMedia},z={getList:$.getFilters,get:$.getFilter,update:$.updateFilter,create:$.createFilter,delete:$.deleteFilter},N={get:T.getAppendListings,getAppendListing:T.getAppendListing,create:T.createAppendListing,update:T.updateAppendListing,delete:T.deleteAppendListing},G={get:_.getAllPermissions},J=x,V=E,q={auth:U,events:W,roles:I,users:O,account:M,mapConfig:D,permissions:G,clientAuthConfig:B,filters:z,listings:j,media:H,appendListings:N,forms:J};exports.account=M,exports.appendListings=N,exports.auth=U,exports.clientAuthConfig=B,exports.default=q,exports.events=W,exports.filters=z,exports.formSubmissions=V,exports.forms=J,exports.listings=j,exports.mapConfig=D,exports.media=H,exports.permissions=G,exports.roles=I,exports.users=O;
2
2
  //# sourceMappingURL=index.cjs.js.map
package/dist/index.d.ts CHANGED
@@ -12,6 +12,8 @@ import { Listing } from "./types/listing";
12
12
  import Filters from "./types/filters/filters";
13
13
  import AppendListing from "./types/appendListing";
14
14
  import Form from "./types/form";
15
+ import FormSubmission, { FormSubmissionStatus } from "./types/formSubmission";
16
+ import ResultsWrapper from "./types/resultsWrapper";
15
17
  export declare const auth: {
16
18
  login: (clientLogInRequest: import("./types/clientLoginRequest").default) => Promise<any>;
17
19
  nextLogin: (credentials: import("./types/credentials").default) => Promise<any>;
@@ -90,8 +92,14 @@ export declare const forms: {
90
92
  updateForm(id: string, form: Form, authToken?: string | null): Promise<void>;
91
93
  deleteForm(id: string, authToken?: string | null): Promise<void>;
92
94
  };
93
- export type { Register, User, Company, Role, HireControlConfig, ClientAuthConfig, Event, Listing, EventDates, EventDateType, EventInstance, MediaType, Filters, AppendListing, Form };
94
- export { EventType, CallToActionType };
95
+ export declare const formSubmissions: {
96
+ submitFormSubmission(formSubmission: FormSubmission, authToken?: string | null): Promise<string>;
97
+ getFormSubmissions(pageSize?: number, pageNumber?: number, type?: string | null, status?: FormSubmissionStatus | null, from?: Date | null, to?: Date | null, authToken?: string | null): Promise<ResultsWrapper<FormSubmission>>;
98
+ exportFormSubmissionsCsv(pageSize?: number, pageNumber?: number, type?: string | null, status?: FormSubmissionStatus | null, from?: Date | null, to?: Date | null, authToken?: string | null): Promise<void>;
99
+ getFormSubmissionTypes(authToken?: string | null): Promise<string[]>;
100
+ };
101
+ export type { Register, User, Company, Role, HireControlConfig, ClientAuthConfig, Event, Listing, EventDates, EventDateType, EventInstance, MediaType, Filters, AppendListing, Form, FormSubmission, ResultsWrapper, };
102
+ export { EventType, CallToActionType, FormSubmissionStatus };
95
103
  declare const hcApi: {
96
104
  auth: {
97
105
  login: (clientLogInRequest: import("./types/clientLoginRequest").default) => Promise<any>;
@@ -0,0 +1,17 @@
1
+ type FormSubmission = {
2
+ id: string;
3
+ formId?: string;
4
+ companyId: number;
5
+ sqlFormId?: number;
6
+ type?: string;
7
+ dateCreated: string;
8
+ status?: FormSubmissionStatus;
9
+ formFields?: Record<string, string>;
10
+ };
11
+ export declare enum FormSubmissionStatus {
12
+ Submitted = 1,
13
+ Hold = 2,
14
+ Rejected = 3,
15
+ Sent = 4
16
+ }
17
+ export default FormSubmission;
@@ -0,0 +1,5 @@
1
+ type ResultsWrapper<T> = {
2
+ items: T[];
3
+ totalCount: number;
4
+ };
5
+ export default ResultsWrapper;
@@ -81,6 +81,26 @@ class FetchHandler {
81
81
  : this.fetchWithoutAuth<T>(endpoint, options);
82
82
  }
83
83
 
84
+ public async getFile(
85
+ endpoint: string,
86
+ auth: boolean = false,
87
+ authToken: string | null = null
88
+ ): Promise<Blob> {
89
+ const options: RequestInit = {
90
+ method: "GET",
91
+ credentials: "include",
92
+ headers:
93
+ auth && authToken ? { Authorization: `Bearer ${authToken}` } : {},
94
+ };
95
+
96
+ const response = await fetch(`${this.apiUrl}${endpoint}`, options);
97
+ if (!response.ok) {
98
+ throw new Error(`Failed to fetch file: ${response.statusText}`);
99
+ }
100
+
101
+ return response.blob();
102
+ }
103
+
84
104
  // Convert object to FormData recursively
85
105
  private convertToFormData(
86
106
  body: any,
@@ -138,9 +158,9 @@ class FetchHandler {
138
158
  // Retry the original request after refreshing the token
139
159
  response = await fetch(`${this.apiUrl}${endpoint}`, options);
140
160
  } else {
141
- throw {
142
- statusCode: response.status,
143
- }
161
+ throw {
162
+ statusCode: response.status,
163
+ };
144
164
  }
145
165
  }
146
166
  return this.handleResponse<T>(response);
package/index.ts CHANGED
@@ -14,6 +14,7 @@ import mediaController from "./controllers/mediaController";
14
14
  import filtersController from "./controllers/filtersController";
15
15
  import appendListingsController from "./controllers/appendListingsController";
16
16
  import formsController from "./controllers/formsController";
17
+ import formSubmissionController from "./controllers/formSubmissionsController";
17
18
 
18
19
  import Register from "./types/register";
19
20
  import User from "./types/user";
@@ -22,11 +23,19 @@ import Company from "./types/company";
22
23
  import HireControlConfig from "./types/hireControlConfig";
23
24
  import ClientAuthConfig from "./types/clientAuthConfig";
24
25
  import MediaType from "./types/media/media";
25
- import Event, { EventDates, EventDateType, EventInstance, EventType, CallToActionType } from "./types/event";
26
+ import Event, {
27
+ EventDates,
28
+ EventDateType,
29
+ EventInstance,
30
+ EventType,
31
+ CallToActionType,
32
+ } from "./types/event";
26
33
  import { Listing } from "./types/listing";
27
34
  import Filters from "./types/filters/filters";
28
35
  import AppendListing from "./types/appendListing";
29
36
  import Form from "./types/form";
37
+ import FormSubmission, { FormSubmissionStatus } from "./types/formSubmission";
38
+ import ResultsWrapper from "./types/resultsWrapper";
30
39
 
31
40
  export const auth = {
32
41
  login: authController.login,
@@ -109,7 +118,7 @@ export const permissions = {
109
118
  };
110
119
 
111
120
  export const forms = formsController;
112
-
121
+ export const formSubmissions = formSubmissionController;
113
122
  //types
114
123
  export type {
115
124
  Register,
@@ -126,10 +135,12 @@ export type {
126
135
  MediaType,
127
136
  Filters,
128
137
  AppendListing,
129
- Form
138
+ Form,
139
+ FormSubmission,
140
+ ResultsWrapper,
130
141
  };
131
142
 
132
- export { EventType, CallToActionType };
143
+ export { EventType, CallToActionType, FormSubmissionStatus };
133
144
 
134
145
  const hcApi = {
135
146
  auth,
@@ -144,7 +155,7 @@ const hcApi = {
144
155
  listings,
145
156
  media,
146
157
  appendListings,
147
- forms
158
+ forms,
148
159
  };
149
160
 
150
161
  export default hcApi;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abcagency/hire-control-sdk",
3
- "version": "1.0.26",
3
+ "version": "1.0.28",
4
4
  "main": "dist/index.cjs.js",
5
5
  "module": "dist/index.esm.js",
6
6
  "types": "dist/index.d.ts",
@@ -0,0 +1,19 @@
1
+ type FormSubmission = {
2
+ id: string;
3
+ formId?: string;
4
+ companyId: number;
5
+ sqlFormId?: number;
6
+ type?: string;
7
+ dateCreated: string;
8
+ status?: FormSubmissionStatus;
9
+ formFields?: Record<string, string>;
10
+ };
11
+
12
+ export enum FormSubmissionStatus {
13
+ Submitted = 1,
14
+ Hold = 2,
15
+ Rejected = 3,
16
+ Sent = 4,
17
+ }
18
+
19
+ export default FormSubmission;
@@ -0,0 +1,6 @@
1
+ type ResultsWrapper<T> = {
2
+ items: T[];
3
+ totalCount: number;
4
+ };
5
+
6
+ export default ResultsWrapper;