woodsportal-client-sdk 1.1.4-dev.57 → 1.1.4-dev.58

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.
@@ -608,6 +608,39 @@ var getParamDetails = (props, isDetailsPage = false) => {
608
608
  };
609
609
  };
610
610
 
611
+ // src/store/index.ts
612
+ function createStore(initializer) {
613
+ let state;
614
+ const listeners = /* @__PURE__ */ new Set();
615
+ const get = () => state;
616
+ const set = (partial) => {
617
+ const prevState = state;
618
+ const partialState = typeof partial === "function" ? partial(state) : partial;
619
+ state = {
620
+ ...state,
621
+ ...partialState
622
+ };
623
+ listeners.forEach(
624
+ (listener) => listener(state, prevState)
625
+ );
626
+ };
627
+ const subscribe = (listener) => {
628
+ listeners.add(listener);
629
+ return () => listeners.delete(listener);
630
+ };
631
+ state = initializer(set, get);
632
+ return {
633
+ getState: get,
634
+ setState: set,
635
+ subscribe
636
+ };
637
+ }
638
+
639
+ // src/utils/getCookieData.ts
640
+ var getAuthSubscriptionType = () => {
641
+ return getCookie("subscriptionType");
642
+ };
643
+
611
644
  // src/breadcrumb/url.ts
612
645
  var useUpdateLink = () => {
613
646
  const updateLink = async (props, displayName = "prm") => {
@@ -709,39 +742,6 @@ var updateBParam = (newValue) => {
709
742
  }
710
743
  };
711
744
 
712
- // src/store/index.ts
713
- function createStore(initializer) {
714
- let state;
715
- const listeners = /* @__PURE__ */ new Set();
716
- const get = () => state;
717
- const set = (partial) => {
718
- const prevState = state;
719
- const partialState = typeof partial === "function" ? partial(state) : partial;
720
- state = {
721
- ...state,
722
- ...partialState
723
- };
724
- listeners.forEach(
725
- (listener) => listener(state, prevState)
726
- );
727
- };
728
- const subscribe = (listener) => {
729
- listeners.add(listener);
730
- return () => listeners.delete(listener);
731
- };
732
- state = initializer(set, get);
733
- return {
734
- getState: get,
735
- setState: set,
736
- subscribe
737
- };
738
- }
739
-
740
- // src/utils/getCookieData.ts
741
- var getAuthSubscriptionType = () => {
742
- return getCookie("subscriptionType");
743
- };
744
-
745
745
  // src/store/use-table.ts
746
746
  var pageLimit = 10;
747
747
  var tableStore = createStore((set, get) => ({
@@ -991,1096 +991,1464 @@ function useTable() {
991
991
  };
992
992
  }
993
993
 
994
- // src/client/index.ts
995
- var recordWriteContext = (paramsObject) => {
996
- if (!paramsObject) {
997
- return void 0;
998
- }
999
- const context = {};
1000
- const keys = [
1001
- "parentObjectTypeId",
1002
- "parentObjectRecordId",
1003
- "mediatorObjectTypeId",
1004
- "mediatorObjectRecordId"
1005
- ];
1006
- keys.forEach((key) => {
1007
- const value = paramsObject[key];
1008
- if (value !== void 0 && value !== null && String(value).length > 0) {
1009
- context[key] = String(value);
1010
- }
1011
- });
1012
- return Object.keys(context).length > 0 ? context : void 0;
1013
- };
1014
- var mergeRecordWriteBody = (payload, paramsObject, options) => {
1015
- const base = { ...payload || {} };
1016
- const context = recordWriteContext(paramsObject);
1017
- if (context) {
1018
- base.context = context;
1019
- }
1020
- if (options && Object.keys(options).length > 0) {
1021
- base.options = options;
1022
- }
1023
- return base;
1024
- };
1025
- var Client = {
1026
- authentication: {
1027
- preLogin: (data) => AuthHttpClient.post(API_ENDPOINTS.PRE_LOGIN, data),
1028
- login: (data) => {
1029
- const queryParams = config.hubId ? { hubId: config.hubId } : null;
1030
- return AuthHttpClient.post(
1031
- generateApiUrl({ route: API_ENDPOINTS.LOGIN, queryParams }),
1032
- data,
1033
- config?.devPortalId && {
1034
- headers: {
1035
- "X-Dev-Portal-Id": config.devPortalId
1036
- }
1037
- }
994
+ // src/store2/store.ts
995
+ function createStore2(initialState) {
996
+ let state = initialState;
997
+ const listeners = /* @__PURE__ */ new Set();
998
+ return {
999
+ getState() {
1000
+ return state;
1001
+ },
1002
+ setState(partial) {
1003
+ state = {
1004
+ ...state,
1005
+ ...partial
1006
+ };
1007
+ listeners.forEach(
1008
+ (listener) => listener(state)
1038
1009
  );
1039
1010
  },
1040
- verifyEmail: (data) => AuthHttpClient.post(API_ENDPOINTS.VERIFY_EMAIL, data),
1041
- resetPasswordVerifyToken: (data) => AuthHttpClient.post(API_ENDPOINTS.RESET_PASSWORD_VERIFY_TOKEN, data),
1042
- resetPassword: (data) => AuthHttpClient.post(API_ENDPOINTS.RESET_PASSWORD, data),
1043
- forgetPassword: (data) => AuthHttpClient.post(API_ENDPOINTS.FORGET_PASSWORD, data),
1044
- registerExistingUser: (data) => AuthHttpClient.post(API_ENDPOINTS.REGISTER_EXISTING_USER, data?.payload),
1045
- verifyEmailResend: (data) => AuthHttpClient.post(API_ENDPOINTS.VERIFY_EMAIL_RESEND, data),
1046
- resendEmail: (data) => AuthHttpClient.post(API_ENDPOINTS.RESEND_EMAIL, data),
1047
- logout: () => HttpClient.post(API_ENDPOINTS.LOGOUT, null)
1048
- },
1049
- sso: {
1050
- getSsoDetails: () => AuthHttpClient.get(API_ENDPOINTS.SSO_DETAILS),
1051
- generateSsoUrl: (payload) => AuthHttpClient.get(generateApiUrl({ route: API_ENDPOINTS.SSO_URL, queryParams: payload?.queryParams })),
1052
- ssoCallback: (payload) => AuthHttpClient.get(generateApiUrl({ route: API_ENDPOINTS.SSO_CALLBACK, queryParams: payload?.queryParams }))
1053
- },
1054
- user: {
1055
- me: () => HttpClient.get(generateApiUrl({ route: API_ENDPOINTS.ME })),
1056
- profile: (payload) => HttpClient.get(generateApiUrl({ route: API_ENDPOINTS.PROFILE, queryParams: payload })),
1057
- changePassword: (data) => HttpClient.post(API_ENDPOINTS.CHANGE_PASSWORD, data)
1011
+ subscribe(listener) {
1012
+ listeners.add(listener);
1013
+ return () => listeners.delete(listener);
1014
+ }
1015
+ };
1016
+ }
1017
+
1018
+ // src/store2/use-form.ts
1019
+ var formStore = createStore2({
1020
+ form: null
1021
+ });
1022
+ var actions = {
1023
+ setFormData(response) {
1024
+ formStore.setState({
1025
+ form: response
1026
+ });
1027
+ }};
1028
+
1029
+ // src/store2/use-table.ts
1030
+ var tableStore2 = createStore2({
1031
+ queryParams: null,
1032
+ multiObjectsQueryParams: {},
1033
+ objectsData: null,
1034
+ tableData: [],
1035
+ tablePrependData: [],
1036
+ hubspotObjectTypeId: "",
1037
+ selectedPipeline: "",
1038
+ viewType: ""
1039
+ });
1040
+ var actions2 = {
1041
+ /** Called from Client.object.list — feeds purgeCrmListCache / purgeCrmRecordCache. */
1042
+ setObjectsQueryParams(params) {
1043
+ tableStore2.setState({
1044
+ queryParams: params
1045
+ });
1058
1046
  },
1059
- pipeline: {
1060
- list: (payload = null, param = null) => {
1061
- const params = { hubspotObjectTypeId: payload?.hubspotObjectTypeId };
1062
- const { getParamDetails: getParamDetails2 } = routeParam;
1063
- const { paramsObject } = getParamDetails2({ type: payload?.componentName });
1064
- const userData = getProfileData();
1065
- const apiParams = {};
1066
- if (paramsObject?.parentObjectTypeId) {
1067
- apiParams.parentObjectTypeId = paramsObject?.parentObjectTypeId;
1068
- } else if (payload?.isHome && userData?.data?.info?.objectTypeId && !param?.isPrimaryCompany) {
1069
- apiParams.parentObjectTypeId = userData?.data?.info?.objectTypeId;
1070
- } else if (payload?.isHome && userData?.data?.info?.objectTypeId && param?.isPrimaryCompany) {
1071
- apiParams.parentObjectTypeId = "0-2";
1072
- }
1073
- apiParams.isPrimaryCompany = param?.isPrimaryCompany;
1074
- apiParams.cache = payload?.cache;
1075
- const apiUrl = generateApiUrl({ route: API_ENDPOINTS.PIPELINES, params, queryParams: apiParams });
1076
- return HttpClient.get(apiUrl);
1047
+ /** Called from Client.object.sideBarList — feeds purgeCrmListCache for sidebarTable writes. */
1048
+ setMultiObjectsQueryParams(hubspotObjectTypeId, params) {
1049
+ if (!hubspotObjectTypeId) {
1050
+ return;
1077
1051
  }
1052
+ const state = tableStore2.getState();
1053
+ tableStore2.setState({
1054
+ multiObjectsQueryParams: {
1055
+ ...state.multiObjectsQueryParams,
1056
+ [String(hubspotObjectTypeId)]: params
1057
+ }
1058
+ });
1078
1059
  },
1079
- stage: {
1080
- list: (props = null) => {
1081
- const params = {
1082
- // hubId: config.hubId,
1083
- // portalId: portalId,
1084
- objectTypeId: props?.params?.objectTypeId,
1085
- pipelineId: props?.params?.pipelineId
1086
- };
1087
- const apiUrl = generateApiUrl({ route: API_ENDPOINTS.STAGES, params });
1088
- return HttpClient.get(apiUrl);
1060
+ async setObjectsData(response) {
1061
+ const state = tableStore2.getState();
1062
+ if (response?.info?.viewType == "LIST") {
1063
+ tableStore2.setState({
1064
+ objectsData: response
1065
+ });
1066
+ }
1067
+ if (response?.info?.viewType == "BOARD") {
1068
+ const {
1069
+ stageId
1070
+ } = useTable();
1071
+ if (stageId) {
1072
+ const boardData = { ...state.objectsData };
1073
+ const updatedBoardData = await {
1074
+ ...boardData,
1075
+ data: {
1076
+ ...boardData.data,
1077
+ results: boardData.data.results.map(
1078
+ (item) => String(item.id) === String(stageId) ? {
1079
+ ...item,
1080
+ data: {
1081
+ ...item.data,
1082
+ results: {
1083
+ ...item.data.results,
1084
+ rows: [
1085
+ ...item?.data?.results?.rows ?? [],
1086
+ // keep existing rows
1087
+ ...response?.data?.results?.rows ?? []
1088
+ // prepend new rows
1089
+ ]
1090
+ }
1091
+ }
1092
+ } : item
1093
+ )
1094
+ }
1095
+ };
1096
+ tableStore2.setState({
1097
+ objectsData: updatedBoardData
1098
+ });
1099
+ } else {
1100
+ tableStore2.setState({
1101
+ objectsData: response
1102
+ });
1103
+ }
1089
1104
  }
1090
1105
  },
1091
- object: {
1092
- list: async (payload = null, param = null) => {
1093
- param.cache = payload?.cache !== false ? true : false;
1094
- const params = { hubspotObjectTypeId: payload?.hubspotObjectTypeId };
1095
- const { updateLink, getLinkParams } = useUpdateLink();
1096
- const { getParamDetails: getParamDetails2 } = routeParam;
1097
- const { paramsObject, parentAccessLabel } = getParamDetails2({ type: payload?.componentName });
1098
- const userData = getProfileData();
1099
- const pipeline = payload?.variables?.pipeline;
1100
- const mPipelines = payload?.variables?.mPipelines;
1101
- const mSelectedPipeline = pipeline !== void 0 ? pipeline : payload?.selectedPipeline;
1102
- if (mSelectedPipeline) {
1103
- param.filterValue = mSelectedPipeline;
1104
- } else if (payload?.specPipeLine && payload?.pipeLineId) {
1105
- param.filterValue = payload?.pipeLineId;
1106
- } else if (payload?.hubspotObjectTypeId != "0-3" || payload?.hubspotObjectTypeId != "0-5") {
1107
- param.filterValue = "";
1108
- }
1109
- const fParams = getLinkParams();
1110
- param = { ...payload?.isFristTimeLoadData && fParams && !payload?.isHome ? fParams : param, ...paramsObject };
1111
- if (!payload?.isFristTimeLoadData || !fParams) {
1112
- await updateLink({
1113
- "sort": param?.sort,
1114
- "s": param?.search,
1115
- "fPn": param?.filterPropertyName,
1116
- "fO": param?.filterOperator,
1117
- "fV": param?.filterValue,
1118
- "c": param?.cache !== false,
1119
- "isPC": param?.isPrimaryCompany,
1120
- "v": param?.view,
1121
- "l": param?.limit,
1122
- "p": param?.page,
1123
- "a": param?.after
1124
- });
1125
- }
1126
- if (mPipelines != void 0 && mPipelines?.length === 0 && !payload?.specPipeLine) {
1127
- param.filterValue = "";
1128
- await updateLink({
1129
- "fV": param?.filterValue
1130
- });
1131
- }
1132
- if (mPipelines != void 0 && mPipelines?.length === 1 && !payload?.specPipeLine && mSelectedPipeline != null) {
1133
- param.filterValue = mPipelines[0].pipelineId;
1134
- await updateLink({
1135
- "fV": param?.filterValue
1106
+ setTableData(response, payload) {
1107
+ const state = tableStore2.getState();
1108
+ const viewType = response?.info?.viewType;
1109
+ let newTablePrependData;
1110
+ if (viewType === "BOARD") {
1111
+ const stages = response?.data?.results ?? [];
1112
+ newTablePrependData = state.tablePrependData.map((prependStage) => {
1113
+ const matchingStage = stages.find(
1114
+ (stage) => String(stage.id) === String(prependStage.id)
1115
+ );
1116
+ const rows = matchingStage?.data?.results?.rows ?? [];
1117
+ const rowIds = new Set(
1118
+ rows.map((row) => row.id ?? row.hs_object_id).filter((id) => id != null && id !== "").map((id) => String(id))
1119
+ );
1120
+ const filteredRows = (prependStage?.data?.results?.rows ?? []).filter((item) => {
1121
+ const itemId = item.id ?? item.hs_object_id;
1122
+ if (itemId == null || itemId === "") return true;
1123
+ return !rowIds.has(String(itemId));
1136
1124
  });
1137
- }
1138
- if (payload?.isHome || payload?.hubspotObjectTypeId === "0-5" && payload?.componentName === "object") {
1139
- let parentObjectTypeId = "";
1140
- if (userData?.data?.info?.objectTypeId && !param?.isPrimaryCompany) {
1141
- parentObjectTypeId = userData?.data?.info?.objectTypeId;
1142
- } else if (userData?.data?.info?.objectTypeId && param?.isPrimaryCompany) {
1143
- parentObjectTypeId = "0-2";
1144
- }
1145
- param.parentObjectTypeId = parentObjectTypeId;
1146
- }
1147
- param.parentAccessLabel = parentAccessLabel;
1148
- const {
1149
- stageId,
1150
- nextPage
1151
- } = useTable();
1152
- if (stageId) {
1153
- param.stageId = stageId;
1154
- }
1155
- if (param?.view === "BOARD") {
1156
- param.page = nextPage;
1157
- }
1158
- const apiUrl = generateApiUrl({ route: API_ENDPOINTS.OBJECTS, params, queryParams: param });
1159
- return HttpClient.get(apiUrl);
1160
- },
1161
- sideBarList: async (payload = null) => {
1162
- const hubspotObjectTypeId = payload?.hubspotObjectTypeId;
1163
- const params = { hubspotObjectTypeId };
1164
- const queryParams = payload.param;
1165
- const apiUrl = generateApiUrl({ route: API_ENDPOINTS.OBJECTS, params, queryParams });
1166
- return HttpClient.get(apiUrl);
1167
- },
1168
- form: (payload = null) => {
1169
- const params = { hubspotObjectTypeId: payload?.hubspotObjectTypeId };
1170
- const apiUrl = generateApiUrl({ route: API_ENDPOINTS.OBJECTS_FORM, params, queryParams: payload?.params });
1171
- return HttpClient.get(apiUrl);
1172
- },
1173
- objectFormOptions: (payload = null) => {
1174
- const params = {
1175
- formId: payload?.formId,
1176
- objectTypeId: payload?.objectTypeId ?? payload?.hubspotObjectTypeId
1177
- };
1178
- const apiUrl = generateApiUrl({ route: API_ENDPOINTS.OBJECTS_FORM_OPTIONS, params, queryParams: payload?.params });
1179
- return HttpClient.get(apiUrl);
1180
- },
1181
- create: (props = null) => {
1182
- const { getParamDetails: getParamDetailsForCreate } = routeParam;
1183
- const { paramsObject } = getParamDetailsForCreate({ type: props?.componentName });
1184
- const cardParentMerge = props?.componentName === "association" ? true : false;
1185
- const body = mergeRecordWriteBody(props?.payload, paramsObject, {
1186
- cardParentMerge,
1187
- addAnother: props?.params?.addAnother
1125
+ return {
1126
+ ...prependStage,
1127
+ data: {
1128
+ ...prependStage.data,
1129
+ results: {
1130
+ ...prependStage.data?.results,
1131
+ rows: filteredRows
1132
+ }
1133
+ }
1134
+ };
1188
1135
  });
1189
- const params = { hubspotObjectTypeId: props?.hubspotObjectTypeId };
1190
- const apiUrl = generateApiUrl({ route: API_ENDPOINTS.RECORDS_CREATE, params, queryParams: props?.params });
1191
- return HttpClient.post(apiUrl, body);
1192
- },
1193
- createExisting: (props = null) => {
1194
- const { getLinkParams } = useUpdateLink();
1195
- const fParams = getLinkParams();
1196
- const queryParams = { ...fParams, ...props?.params };
1197
- const params = {
1198
- fromObjectTypeId: props?.fromObjectTypeId ?? props?.hubspotObjectTypeId,
1199
- fromRecordId: props?.fromRecordId,
1200
- toObjectTypeId: props?.toObjectTypeId
1201
- };
1202
- const payload = props.payload;
1203
- const apiUrl = generateApiUrl({ route: API_ENDPOINTS.RECORDS_ASSOCIATE, params, queryParams });
1204
- return HttpClient.post(apiUrl, payload);
1205
- },
1206
- removeExisting: (props = null) => {
1207
- const { getParamDetails: getParamDetailsForRemove } = routeParam;
1208
- const { paramsObject } = getParamDetailsForRemove({ type: props?.componentName });
1209
- const body = mergeRecordWriteBody(props?.payload, paramsObject, void 0);
1210
- const params = {
1211
- fromObjectTypeId: props?.fromObjectTypeId ?? props?.hubspotObjectTypeId,
1212
- fromRecordId: props?.fromRecordId,
1213
- toObjectTypeId: props?.toObjectTypeId
1214
- };
1215
- const apiUrl = generateApiUrl({ route: API_ENDPOINTS.RECORDS_DISASSOCIATE, params });
1216
- return HttpClient.delete(apiUrl, { data: body });
1217
- },
1218
- details: (props = null) => {
1219
- const { paramsObject: urlParam, parentAccessLabel } = getParamDetails("", true);
1220
- const hubspotObjectTypeId = ticketHubspotObjectTypeId();
1221
- const params = {
1222
- // hubId: config.hubId,
1223
- // portalId: portalId,
1224
- objectId: props?.params?.objectId,
1225
- id: props?.params?.id
1226
- };
1227
- const queryParams = {
1228
- parentAccessLabel,
1229
- ...props?.queryParams,
1230
- ...urlParam
1231
- };
1232
- if (hubspotObjectTypeId) queryParams.parentObjectTypeId = hubspotObjectTypeId;
1233
- const apiUrl = generateApiUrl({ route: API_ENDPOINTS.OBJECTS_DETAILS, params, queryParams });
1234
- return HttpClient.get(apiUrl);
1235
- },
1236
- update: (props = null) => {
1237
- const hubspotObjectTypeId = ticketHubspotObjectTypeId();
1238
- const params = {
1239
- objectId: props?.params?.objectId,
1240
- id: props?.params?.id
1241
- };
1242
- const { getParamDetails: getParamDetailsForUpdate } = routeParam;
1243
- const { paramsObject } = getParamDetailsForUpdate({ type: props?.componentName });
1244
- const cardParentMerge = props?.componentName === "association" ? true : false;
1245
- const rawPayload = props?.payload || {};
1246
- const properties = rawPayload.properties ?? rawPayload.propertyPayload ?? rawPayload;
1247
- const body = mergeRecordWriteBody(
1248
- { properties },
1249
- paramsObject,
1250
- { cardParentMerge }
1136
+ } else {
1137
+ const rows = response?.data?.results?.rows ?? [];
1138
+ const rowIds = new Set(
1139
+ rows.map((row) => row.id ?? row.hs_object_id).filter((id) => id != null && id !== "").map((id) => String(id))
1251
1140
  );
1252
- const queryParams = {};
1253
- if (hubspotObjectTypeId) queryParams.parentObjectTypeId = hubspotObjectTypeId;
1254
- const apiUrl = generateApiUrl({ route: API_ENDPOINTS.RECORDS_UPDATE, params, queryParams });
1255
- return HttpClient.put(apiUrl, body);
1256
- }
1257
- },
1258
- note: {
1259
- list: (props = null) => {
1260
- const params = {
1261
- // hubId: config.hubId,
1262
- // portalId: portalId,
1263
- objectId: props?.params?.objectId,
1264
- id: props?.params?.id
1265
- };
1266
- const apiUrl = generateApiUrl({ route: API_ENDPOINTS.NOTES, params, queryParams: props?.queryParams });
1267
- return HttpClient.get(apiUrl);
1268
- },
1269
- create: (props = null) => {
1270
- const params = { hubspotObjectTypeId: props?.hubspotObjectTypeId, ...props.params };
1271
- const queryParams = props.queryParams;
1272
- const payload = props.payload;
1273
- const apiUrl = generateApiUrl({ route: API_ENDPOINTS.NOTES_CREATE, params, queryParams });
1274
- return HttpClient.post(apiUrl, payload);
1275
- },
1276
- update: (props = null) => {
1277
- const params = {
1278
- // hubId: config.hubId,
1279
- // portalId: portalId,
1280
- objectId: props?.params?.objectId,
1281
- id: props?.params?.id,
1282
- note_id: props?.params?.note_id
1283
- };
1284
- const { paramsObject: queryParams } = getParamDetails();
1285
- const apiUrl = generateApiUrl({ route: API_ENDPOINTS.NOTES_DETAILS_UPDATE, params, queryParams });
1286
- return HttpClient.put(apiUrl, props.payload);
1287
- },
1288
- image: (props = null) => {
1289
- const params = { hubspotObjectTypeId: props?.hubspotObjectTypeId, ...props.params };
1290
- const queryParams = props.queryParams;
1291
- const payload = props.payload;
1292
- const axiosConfig = props.config || {};
1293
- const apiUrl = generateApiUrl({ route: API_ENDPOINTS.NOTES_IMAGE_UPLOAD, params, queryParams });
1294
- return HttpClient.post(apiUrl, payload, {
1295
- headers: {
1296
- "Content-Type": "multipart/form-data"
1297
- },
1298
- ...axiosConfig
1299
- });
1300
- },
1301
- attachment: (props = null) => {
1302
- const params = { hubspotObjectTypeId: props?.hubspotObjectTypeId, ...props.params };
1303
- const queryParams = props.queryParams;
1304
- const payload = props.payload;
1305
- const axiosConfig = props.config || {};
1306
- const apiUrl = generateApiUrl({ route: API_ENDPOINTS.NOTES_ATTACHMENT_UPLOAD, params, queryParams });
1307
- return HttpClient.post(apiUrl, payload, {
1308
- headers: {
1309
- "Content-Type": "multipart/form-data"
1310
- },
1311
- ...axiosConfig
1141
+ newTablePrependData = state.tablePrependData.filter((item) => {
1142
+ const itemId = item.id ?? item.hs_object_id;
1143
+ if (itemId == null || itemId === "") return true;
1144
+ return !rowIds.has(String(itemId));
1312
1145
  });
1313
1146
  }
1314
- },
1315
- email: {
1316
- list: (props = null) => {
1317
- const params = {
1318
- // hubId: config.hubId,
1319
- // portalId: portalId,
1320
- objectId: props?.params?.objectId,
1321
- id: props?.params?.id
1322
- };
1323
- const apiUrl = generateApiUrl({ route: API_ENDPOINTS.EMAILS, params, queryParams: props?.queryParams });
1324
- return HttpClient.get(apiUrl);
1325
- },
1326
- create: (props = null) => {
1327
- const params = { hubspotObjectTypeId: props?.hubspotObjectTypeId, ...props.params };
1328
- const queryParams = props.queryParams;
1329
- const payload = props.payload;
1330
- const apiUrl = generateApiUrl({ route: API_ENDPOINTS.EMAILS_CREATE, params, queryParams });
1331
- return HttpClient.post(apiUrl, payload);
1332
- },
1333
- update: (props = null) => {
1334
- const params = {
1335
- // hubId: config.hubId,
1336
- // portalId: portalId,
1337
- objectId: props?.params?.objectId,
1338
- id: props?.params?.id,
1339
- email_id: props?.params?.email_id ?? props?.params?.note_id
1340
- };
1341
- const { paramsObject: queryParams } = getParamDetails();
1342
- const apiUrl = generateApiUrl({ route: API_ENDPOINTS.EMAILS_DETAILS_UPDATE, params, queryParams });
1343
- return HttpClient.put(apiUrl, props.payload);
1344
- },
1345
- image: (props = null) => {
1346
- const params = { hubspotObjectTypeId: props?.hubspotObjectTypeId, ...props.params };
1347
- const queryParams = props.queryParams;
1348
- const payload = props.payload;
1349
- const axiosConfig = props.config || {};
1350
- const apiUrl = generateApiUrl({ route: API_ENDPOINTS.EMAILS_IMAGE_UPLOAD, params, queryParams });
1351
- return HttpClient.post(apiUrl, payload, {
1352
- headers: {
1353
- "Content-Type": "multipart/form-data"
1354
- },
1355
- ...axiosConfig
1356
- });
1357
- },
1358
- attachment: (props = null) => {
1359
- const params = { hubspotObjectTypeId: props?.hubspotObjectTypeId, ...props.params };
1360
- const queryParams = props.queryParams;
1361
- const payload = props.payload;
1362
- const axiosConfig = props.config || {};
1363
- const apiUrl = generateApiUrl({ route: API_ENDPOINTS.EMAILS_ATTACHMENT_UPLOAD, params, queryParams });
1364
- return HttpClient.post(apiUrl, payload, {
1365
- headers: {
1366
- "Content-Type": "multipart/form-data"
1367
- },
1368
- ...axiosConfig
1369
- });
1147
+ const hubspotObjectTypeId = payload?.hubspotObjectTypeId;
1148
+ const selectedPipeline = payload?.selectedPipeline;
1149
+ if (response?.data?.total < 1 || payload?.componentName) {
1150
+ newTablePrependData = [];
1370
1151
  }
1371
- },
1372
- cache: {
1373
- purge: (body, headers) => {
1374
- const apiUrl = generateApiUrl({ route: API_ENDPOINTS.CACHE_PURGE });
1375
- return HttpClient.post(apiUrl, body, headers ? { headers } : void 0);
1376
- },
1377
- purgeStatus: (purgeJobId) => {
1378
- const apiUrl = generateApiUrl({
1379
- route: API_ENDPOINTS.CACHE_PURGE_STATUS,
1380
- params: { purgeJobId }
1381
- });
1382
- return HttpClient.get(apiUrl);
1152
+ if (state.viewType && state.viewType != viewType) {
1153
+ newTablePrependData = [];
1383
1154
  }
1155
+ if (state.hubspotObjectTypeId && state.hubspotObjectTypeId != hubspotObjectTypeId) {
1156
+ newTablePrependData = [];
1157
+ }
1158
+ if (state.selectedPipeline && state.selectedPipeline != selectedPipeline) {
1159
+ newTablePrependData = [];
1160
+ }
1161
+ if (payload.isFristTimeLoadData) {
1162
+ newTablePrependData = [];
1163
+ }
1164
+ tableStore2.setState({
1165
+ tableData: response,
1166
+ tablePrependData: newTablePrependData || [],
1167
+ hubspotObjectTypeId,
1168
+ viewType
1169
+ });
1384
1170
  },
1385
- file: {
1386
- list: (props = null) => {
1387
- const params = {
1388
- // hubId: config.hubId,
1389
- // portalId: portalId,
1390
- objectId: props?.params?.objectId,
1391
- id: props?.params?.id
1392
- };
1393
- const apiUrl = generateApiUrl({ route: API_ENDPOINTS.FILES, params, queryParams: props?.queryParams });
1394
- return HttpClient.get(apiUrl);
1395
- },
1396
- details: (props = null) => {
1397
- const params = {
1398
- // hubId: config.hubId,
1399
- // portalId: portalId,
1400
- objectId: props?.params?.objectId,
1401
- id: props?.params?.id,
1402
- rowId: props?.params?.rowId
1403
- };
1404
- const apiUrl = generateApiUrl({ route: API_ENDPOINTS.FILE, params, queryParams: props?.queryParams });
1405
- return HttpClient.get(apiUrl);
1406
- },
1407
- download: (props = null) => {
1408
- const params = {
1409
- objectId: props?.params?.objectId,
1410
- id: props?.params?.id,
1411
- rowId: props?.params?.rowId
1412
- };
1413
- const apiUrl = generateApiUrl({ route: API_ENDPOINTS.FILE_DOWNLOAD, params, queryParams: props?.queryParams });
1414
- return HttpClient.post(apiUrl, {});
1415
- },
1416
- addFolder: (props = null) => {
1417
- const params = { hubspotObjectTypeId: props?.hubspotObjectTypeId, ...props.params };
1418
- const queryParams = props.queryParams;
1419
- const payload = props.payload;
1420
- const apiUrl = generateApiUrl({ route: API_ENDPOINTS.FILES_CREATE_FOLDER, params, queryParams });
1421
- return HttpClient.post(apiUrl, payload);
1422
- },
1423
- addFile: (props = null) => {
1424
- const params = { hubspotObjectTypeId: props?.hubspotObjectTypeId, ...props.params };
1425
- const queryParams = props.queryParams;
1426
- const payload = props.payload;
1427
- const axiosConfig = props.config || {};
1428
- const apiUrl = generateApiUrl({ route: API_ENDPOINTS.FILES_UPLOAD, params, queryParams });
1429
- return HttpClient.post(apiUrl, payload, {
1430
- headers: {
1431
- "Content-Type": "multipart/form-data"
1171
+ modifiedObjectsData(results) {
1172
+ const state = tableStore2.getState();
1173
+ const tablePrependData = state.tablePrependData;
1174
+ const modifiedData = results.map((result) => {
1175
+ const matchedPrepend = tablePrependData.find(
1176
+ (item) => String(item?.id) === String(result?.id)
1177
+ );
1178
+ if (!matchedPrepend) {
1179
+ return result;
1180
+ }
1181
+ const prependRows = matchedPrepend?.data?.results?.rows ?? [];
1182
+ const prependCards = prependRows.map((row) => ({
1183
+ id: row.hs_object_id,
1184
+ ...row
1185
+ }));
1186
+ return {
1187
+ ...result,
1188
+ // prepend in results.rows
1189
+ data: {
1190
+ ...result.data,
1191
+ results: {
1192
+ ...result.data.results,
1193
+ rows: [
1194
+ ...prependRows,
1195
+ ...result?.data?.results?.rows ?? []
1196
+ ]
1197
+ }
1432
1198
  },
1433
- ...axiosConfig
1434
- });
1199
+ // prepend in cards
1200
+ cards: [
1201
+ ...prependCards,
1202
+ ...result?.cards ?? []
1203
+ ]
1204
+ };
1205
+ });
1206
+ tableStore2.setState({
1207
+ objectsData: modifiedData
1208
+ });
1209
+ },
1210
+ clearTablePrependData() {
1211
+ tableStore2.setState({
1212
+ tablePrependData: []
1213
+ });
1214
+ },
1215
+ async setTablePrependData(response, props) {
1216
+ const state = tableStore2.getState();
1217
+ const formState = formStore.getState();
1218
+ let rows = [];
1219
+ if (state.tableData?.info?.viewType == "BOARD") {
1220
+ if (response === "loading") {
1221
+ const responseData = state.tableData?.data?.results ?? [];
1222
+ const pipelineStage = props?.payload?.propertyPayload?.hs_pipeline_stage || props?.payload?.propertyPayload?.dealstage || formState?.form?.data?.pipelineDefaults?.defaultStage?.id;
1223
+ rows = responseData.map(
1224
+ ({ id, data }) => {
1225
+ const matchedPrepend = state.tablePrependData.find(
1226
+ (item) => String(item.id) === String(id)
1227
+ );
1228
+ const prependRows = matchedPrepend?.data?.results?.rows ?? [];
1229
+ const newRow = String(id) === String(pipelineStage) ? [
1230
+ (data?.results?.columns ?? []).reduce(
1231
+ (obj, column) => {
1232
+ obj[column.key] = "loading";
1233
+ return obj;
1234
+ },
1235
+ {}
1236
+ )
1237
+ ] : [];
1238
+ return {
1239
+ id,
1240
+ data: {
1241
+ results: {
1242
+ columns: data?.results?.columns ?? [],
1243
+ // prepend loading row + prepend rows
1244
+ rows: [
1245
+ ...newRow,
1246
+ ...prependRows
1247
+ ]
1248
+ }
1249
+ }
1250
+ };
1251
+ }
1252
+ );
1253
+ } else {
1254
+ const data = response?.data;
1255
+ const hs_pipeline_stage = data?.hs_pipeline_stage?.value?.value || data?.dealstage?.value?.value;
1256
+ if (!data) {
1257
+ tableStore2.setState({
1258
+ tablePrependData: []
1259
+ });
1260
+ }
1261
+ rows = state?.tablePrependData.map((row) => {
1262
+ const matchedPrepend = state.tablePrependData.find(
1263
+ (item) => String(item.id) === String(row.id)
1264
+ );
1265
+ const prependRows = matchedPrepend?.data?.results?.rows ?? [];
1266
+ if (String(row.id) === String(hs_pipeline_stage)) {
1267
+ const updatedRow = (row?.data?.results?.columns ?? []).reduce(
1268
+ (obj, column) => {
1269
+ const key = column.key;
1270
+ obj[key] = data?.[key]?.value ?? data?.[key] ?? "";
1271
+ return obj;
1272
+ },
1273
+ {}
1274
+ );
1275
+ prependRows[0] = updatedRow;
1276
+ return {
1277
+ ...row,
1278
+ data: {
1279
+ ...row.data,
1280
+ results: {
1281
+ ...row.data.results,
1282
+ rows: prependRows
1283
+ }
1284
+ }
1285
+ };
1286
+ }
1287
+ return row;
1288
+ });
1289
+ }
1290
+ } else if (state.tableData?.info?.viewType == "LIST") {
1291
+ if (response === "loading") {
1292
+ const row = await state.tableData?.data?.results?.columns.reduce((acc, item) => {
1293
+ if (!item.hidden) {
1294
+ acc[item.key] = "loading";
1295
+ }
1296
+ return acc;
1297
+ }, {});
1298
+ rows = [row, ...state.tablePrependData];
1299
+ } else if (response?.data) {
1300
+ const data = response?.data;
1301
+ if (!data) {
1302
+ tableStore2.setState({
1303
+ tablePrependData: []
1304
+ });
1305
+ }
1306
+ const row = await Object.fromEntries(
1307
+ Object.entries(data).map(([key, value]) => [
1308
+ key,
1309
+ value?.value ?? value
1310
+ ])
1311
+ );
1312
+ rows = [...state.tablePrependData];
1313
+ if (rows.length > 0) {
1314
+ rows[0] = row;
1315
+ } else {
1316
+ rows.push(row);
1317
+ }
1318
+ }
1435
1319
  }
1320
+ tableStore2.setState({
1321
+ tablePrependData: rows
1322
+ });
1436
1323
  }
1437
1324
  };
1438
1325
 
1439
- // src/store2/store.ts
1440
- function createStore2(initialState) {
1441
- let state = initialState;
1442
- const listeners = /* @__PURE__ */ new Set();
1326
+ // src/store2/use-uploader.ts
1327
+ var uploaderStore = createStore2({
1328
+ attachments: []
1329
+ });
1330
+ function toAttachmentSummary(attachment) {
1443
1331
  return {
1444
- getState() {
1445
- return state;
1446
- },
1447
- setState(partial) {
1448
- state = {
1449
- ...state,
1450
- ...partial
1451
- };
1452
- listeners.forEach(
1453
- (listener) => listener(state)
1454
- );
1455
- },
1456
- subscribe(listener) {
1457
- listeners.add(listener);
1458
- return () => listeners.delete(listener);
1459
- }
1332
+ createdAt: attachment.createdAt,
1333
+ id: attachment.id,
1334
+ name: attachment.name,
1335
+ size: attachment.size,
1336
+ type: attachment.type,
1337
+ updatedAt: attachment.updatedAt
1460
1338
  };
1461
1339
  }
1340
+ function resolveAttachmentsFromIds(attachmentIds, storedAttachments) {
1341
+ const raw = typeof attachmentIds === "object" && attachmentIds !== null && "value" in attachmentIds ? attachmentIds.value : attachmentIds;
1342
+ const ids = String(raw ?? "").split(";").map((id) => id.trim()).filter(Boolean);
1343
+ return ids.map((id) => storedAttachments.find((a) => String(a.id) === id)).filter((a) => a != null).map(toAttachmentSummary);
1344
+ }
1345
+ var actions3 = {
1346
+ setAttachment(response) {
1347
+ const data = response?.data;
1348
+ if (!data?.id) return;
1349
+ const state = uploaderStore.getState();
1350
+ const id = String(data.id);
1351
+ const existing = state.attachments;
1352
+ const index = existing.findIndex((item) => String(item.id) === id);
1353
+ const attachments = index >= 0 ? existing.map((item, i) => i === index ? data : item) : [...existing, data];
1354
+ uploaderStore.setState({ attachments });
1355
+ },
1356
+ clearAttachments() {
1357
+ uploaderStore.setState({ attachments: [] });
1358
+ }
1359
+ };
1462
1360
 
1463
- // src/store2/use-form.ts
1464
- var formStore = createStore2({
1465
- form: null
1361
+ // src/store2/use-note.ts
1362
+ var noteStore = createStore2({
1363
+ notes: [],
1364
+ prependNotes: [],
1365
+ id: "",
1366
+ queryParams: null
1466
1367
  });
1467
- var actions = {
1468
- setFormData(response) {
1469
- formStore.setState({
1470
- form: response
1368
+ var actions4 = {
1369
+ /** Called from Client.note.list — feeds purgeEngagementCaches (view: notes). */
1370
+ setListQueryParams(params) {
1371
+ noteStore.setState({
1372
+ queryParams: params
1471
1373
  });
1472
- }};
1473
-
1474
- // src/store2/use-table.ts
1475
- var tableStore2 = createStore2({
1476
- objectsData: null,
1477
- tableData: [],
1478
- tablePrependData: [],
1479
- hubspotObjectTypeId: "",
1480
- selectedPipeline: "",
1481
- viewType: ""
1482
- });
1483
- var actions2 = {
1484
- async setObjectsData(response) {
1485
- const state = tableStore2.getState();
1486
- if (response?.info?.viewType == "LIST") {
1487
- tableStore2.setState({
1488
- objectsData: response
1489
- });
1374
+ },
1375
+ setNotes(response, payload) {
1376
+ const state = noteStore.getState();
1377
+ const rows = response?.data?.results?.rows ?? [];
1378
+ const rowIds = new Set(
1379
+ rows.map((row) => row.id ?? row.hs_object_id).filter((id2) => id2 != null && id2 !== "").map((id2) => String(id2))
1380
+ );
1381
+ let newPrependNotes = state.prependNotes.filter((item) => {
1382
+ const itemId = item.id ?? item.hs_object_id;
1383
+ if (itemId == null || itemId === "") return true;
1384
+ return !rowIds.has(String(itemId));
1385
+ });
1386
+ const id = payload?.params?.id;
1387
+ if (state.id && state.id != id) {
1388
+ newPrependNotes = [];
1490
1389
  }
1491
- if (response?.info?.viewType == "BOARD") {
1492
- const {
1493
- stageId
1494
- } = useTable();
1495
- if (stageId) {
1496
- const boardData = { ...state.objectsData };
1497
- const updatedBoardData = await {
1498
- ...boardData,
1499
- data: {
1500
- ...boardData.data,
1501
- results: boardData.data.results.map(
1502
- (item) => String(item.id) === String(stageId) ? {
1503
- ...item,
1504
- data: {
1505
- ...item.data,
1506
- results: {
1507
- ...item.data.results,
1508
- rows: [
1509
- ...item?.data?.results?.rows ?? [],
1510
- // keep existing rows
1511
- ...response?.data?.results?.rows ?? []
1512
- // prepend new rows
1513
- ]
1514
- }
1515
- }
1516
- } : item
1517
- )
1518
- }
1519
- };
1520
- tableStore2.setState({
1521
- objectsData: updatedBoardData
1390
+ noteStore.setState({
1391
+ notes: response,
1392
+ prependNotes: newPrependNotes,
1393
+ id
1394
+ });
1395
+ },
1396
+ async setPrependNote(response) {
1397
+ const state = noteStore.getState();
1398
+ let rows = [];
1399
+ if (response === "loading") {
1400
+ const row = await state.notes?.data?.results?.columns.reduce((acc, item) => {
1401
+ if (!item.hidden) {
1402
+ acc[item.key] = "loading";
1403
+ }
1404
+ return acc;
1405
+ }, {});
1406
+ rows = [row, ...state.prependNotes];
1407
+ } else if (response?.data) {
1408
+ const data = response?.data;
1409
+ if (!data) {
1410
+ noteStore.setState({
1411
+ prependNotes: []
1522
1412
  });
1413
+ }
1414
+ const storedAttachments = uploaderStore.getState().attachments;
1415
+ const row = Object.fromEntries(
1416
+ Object.entries(data).map(([key, value]) => {
1417
+ if (key === "hs_attachment_ids") {
1418
+ return [
1419
+ key,
1420
+ resolveAttachmentsFromIds(value, storedAttachments)
1421
+ ];
1422
+ }
1423
+ return [key, value?.value ?? value];
1424
+ })
1425
+ );
1426
+ rows = [...state.prependNotes];
1427
+ if (rows.length > 0) {
1428
+ rows[0] = row;
1523
1429
  } else {
1524
- tableStore2.setState({
1525
- objectsData: response
1526
- });
1430
+ rows.push(row);
1527
1431
  }
1528
1432
  }
1433
+ noteStore.setState({
1434
+ prependNotes: rows
1435
+ });
1529
1436
  },
1530
- setTableData(response, payload) {
1531
- const state = tableStore2.getState();
1532
- const viewType = response?.info?.viewType;
1533
- let newTablePrependData;
1534
- if (viewType === "BOARD") {
1535
- const stages = response?.data?.results ?? [];
1536
- newTablePrependData = state.tablePrependData.map((prependStage) => {
1537
- const matchingStage = stages.find(
1538
- (stage) => String(stage.id) === String(prependStage.id)
1539
- );
1540
- const rows = matchingStage?.data?.results?.rows ?? [];
1541
- const rowIds = new Set(
1542
- rows.map((row) => row.id ?? row.hs_object_id).filter((id) => id != null && id !== "").map((id) => String(id))
1543
- );
1544
- const filteredRows = (prependStage?.data?.results?.rows ?? []).filter((item) => {
1545
- const itemId = item.id ?? item.hs_object_id;
1546
- if (itemId == null || itemId === "") return true;
1547
- return !rowIds.has(String(itemId));
1548
- });
1549
- return {
1550
- ...prependStage,
1437
+ clearPrependNotes() {
1438
+ noteStore.setState({
1439
+ prependNotes: []
1440
+ });
1441
+ actions3.clearAttachments();
1442
+ },
1443
+ async updatePrependNote(response) {
1444
+ const responseData = { ...response };
1445
+ const state = noteStore.getState();
1446
+ const prependNotes = state.prependNotes || [];
1447
+ const note = response.data || null;
1448
+ const storedAttachments = uploaderStore.getState().attachments;
1449
+ const notes = prependNotes.map(
1450
+ (item) => item?.hs_object_id === note?.hs_object_id?.value ? {
1451
+ ...item,
1452
+ ...Object.fromEntries(
1453
+ Object.entries(note).map(([key, value]) => {
1454
+ if (key === "hs_attachment_ids") {
1455
+ return [
1456
+ key,
1457
+ resolveAttachmentsFromIds(value, storedAttachments)
1458
+ ];
1459
+ }
1460
+ return [key, value?.value ?? value];
1461
+ })
1462
+ )
1463
+ } : item
1464
+ );
1465
+ noteStore.setState({
1466
+ prependNotes: notes
1467
+ });
1468
+ if (responseData?.data?.hs_attachment_ids != null) {
1469
+ const noteObjectId = note?.hs_object_id?.value;
1470
+ const rows = state.notes?.data?.results?.rows ?? [];
1471
+ const matchingRow = rows.find(
1472
+ (row) => String(row.hs_object_id) === String(noteObjectId)
1473
+ );
1474
+ const originalPrependItem = prependNotes.find(
1475
+ (item) => String(item?.hs_object_id) === String(noteObjectId)
1476
+ );
1477
+ const existingAttachments = matchingRow?.hs_attachment_ids ?? originalPrependItem?.hs_attachment_ids ?? [];
1478
+ const newAttachments = resolveAttachmentsFromIds(
1479
+ responseData.data.hs_attachment_ids,
1480
+ storedAttachments
1481
+ );
1482
+ const mergedAttachments = [
1483
+ ...existingAttachments,
1484
+ ...newAttachments.filter(
1485
+ (attachment) => !existingAttachments.some(
1486
+ (existing) => String(existing.id) === String(attachment.id)
1487
+ )
1488
+ )
1489
+ ];
1490
+ const stateUpdates = {};
1491
+ if (matchingRow && state.notes?.data?.results) {
1492
+ stateUpdates.notes = {
1493
+ ...state.notes,
1551
1494
  data: {
1552
- ...prependStage.data,
1495
+ ...state.notes.data,
1553
1496
  results: {
1554
- ...prependStage.data?.results,
1555
- rows: filteredRows
1497
+ ...state.notes.data.results,
1498
+ rows: rows.map(
1499
+ (row) => String(row.hs_object_id) === String(noteObjectId) ? { ...row, hs_attachment_ids: mergedAttachments } : row
1500
+ )
1556
1501
  }
1557
1502
  }
1558
1503
  };
1559
- });
1560
- } else {
1561
- const rows = response?.data?.results?.rows ?? [];
1562
- const rowIds = new Set(
1563
- rows.map((row) => row.id ?? row.hs_object_id).filter((id) => id != null && id !== "").map((id) => String(id))
1564
- );
1565
- newTablePrependData = state.tablePrependData.filter((item) => {
1566
- const itemId = item.id ?? item.hs_object_id;
1567
- if (itemId == null || itemId === "") return true;
1568
- return !rowIds.has(String(itemId));
1569
- });
1570
- }
1571
- const hubspotObjectTypeId = payload?.hubspotObjectTypeId;
1572
- const selectedPipeline = payload?.selectedPipeline;
1573
- if (response?.data?.total < 1 || payload?.componentName) {
1574
- newTablePrependData = [];
1575
- }
1576
- if (state.viewType && state.viewType != viewType) {
1577
- newTablePrependData = [];
1578
- }
1579
- if (state.hubspotObjectTypeId && state.hubspotObjectTypeId != hubspotObjectTypeId) {
1580
- newTablePrependData = [];
1581
- }
1582
- if (state.selectedPipeline && state.selectedPipeline != selectedPipeline) {
1583
- newTablePrependData = [];
1504
+ }
1505
+ if (originalPrependItem) {
1506
+ stateUpdates.prependNotes = prependNotes.map(
1507
+ (item) => String(item?.hs_object_id) === String(noteObjectId) ? { ...item, hs_attachment_ids: mergedAttachments } : item
1508
+ );
1509
+ }
1510
+ if (Object.keys(stateUpdates).length > 0) {
1511
+ noteStore.setState(stateUpdates);
1512
+ }
1513
+ responseData.data.hs_attachment_ids = mergedAttachments;
1584
1514
  }
1585
- if (payload.isFristTimeLoadData) {
1586
- newTablePrependData = [];
1515
+ return responseData;
1516
+ }
1517
+ };
1518
+
1519
+ // src/store2/use-email.ts
1520
+ var emailStore = createStore2({
1521
+ emails: [],
1522
+ prependEmails: [],
1523
+ id: "",
1524
+ queryParams: null
1525
+ });
1526
+ var actions5 = {
1527
+ /** Called from Client.email.list — feeds purgeEngagementCaches (view: emails). */
1528
+ setListQueryParams(params) {
1529
+ emailStore.setState({
1530
+ queryParams: params
1531
+ });
1532
+ },
1533
+ setEmails(response, payload) {
1534
+ const state = emailStore.getState();
1535
+ const rows = response?.data?.results?.rows ?? [];
1536
+ const rowIds = new Set(
1537
+ rows.map((row) => row.id ?? row.hs_object_id).filter((id2) => id2 != null && id2 !== "").map((id2) => String(id2))
1538
+ );
1539
+ let newPrependEmails = state.prependEmails.filter((item) => {
1540
+ const itemId = item.id ?? item.hs_object_id;
1541
+ if (itemId == null || itemId === "") return true;
1542
+ return !rowIds.has(String(itemId));
1543
+ });
1544
+ const id = payload?.params?.id;
1545
+ if (state.id && state.id != id) {
1546
+ newPrependEmails = [];
1587
1547
  }
1588
- tableStore2.setState({
1589
- tableData: response,
1590
- tablePrependData: newTablePrependData || [],
1591
- hubspotObjectTypeId,
1592
- viewType
1548
+ emailStore.setState({
1549
+ emails: response,
1550
+ prependEmails: newPrependEmails,
1551
+ id
1593
1552
  });
1594
1553
  },
1595
- modifiedObjectsData(results) {
1596
- const state = tableStore2.getState();
1597
- const tablePrependData = state.tablePrependData;
1598
- const modifiedData = results.map((result) => {
1599
- const matchedPrepend = tablePrependData.find(
1600
- (item) => String(item?.id) === String(result?.id)
1601
- );
1602
- if (!matchedPrepend) {
1603
- return result;
1554
+ async setPrependEmail(response) {
1555
+ const state = emailStore.getState();
1556
+ let rows = [];
1557
+ if (response === "loading") {
1558
+ const row = await state.emails?.data?.results?.columns.reduce((acc, item) => {
1559
+ if (!item.hidden) {
1560
+ acc[item.key] = "loading";
1561
+ }
1562
+ return acc;
1563
+ }, {});
1564
+ rows = [row, ...state.prependEmails];
1565
+ } else if (response?.data) {
1566
+ const data = response?.data;
1567
+ if (!data) {
1568
+ emailStore.setState({
1569
+ prependEmails: []
1570
+ });
1604
1571
  }
1605
- const prependRows = matchedPrepend?.data?.results?.rows ?? [];
1606
- const prependCards = prependRows.map((row) => ({
1607
- id: row.hs_object_id,
1608
- ...row
1609
- }));
1610
- return {
1611
- ...result,
1612
- // prepend in results.rows
1613
- data: {
1614
- ...result.data,
1615
- results: {
1616
- ...result.data.results,
1617
- rows: [
1618
- ...prependRows,
1619
- ...result?.data?.results?.rows ?? []
1620
- ]
1572
+ const storedAttachments = uploaderStore.getState().attachments;
1573
+ const row = Object.fromEntries(
1574
+ Object.entries(data).map(([key, value]) => {
1575
+ if (key === "hs_attachment_ids") {
1576
+ return [
1577
+ key,
1578
+ resolveAttachmentsFromIds(value, storedAttachments)
1579
+ ];
1621
1580
  }
1622
- },
1623
- // prepend in cards
1624
- cards: [
1625
- ...prependCards,
1626
- ...result?.cards ?? []
1627
- ]
1628
- };
1629
- });
1630
- tableStore2.setState({
1631
- objectsData: modifiedData
1581
+ return [key, value?.value ?? value];
1582
+ })
1583
+ );
1584
+ rows = [...state.prependEmails];
1585
+ if (rows.length > 0) {
1586
+ rows[0] = row;
1587
+ } else {
1588
+ rows.push(row);
1589
+ }
1590
+ }
1591
+ emailStore.setState({
1592
+ prependEmails: rows
1632
1593
  });
1633
1594
  },
1634
- clearTablePrependData() {
1635
- tableStore2.setState({
1636
- tablePrependData: []
1595
+ clearPrependEmails() {
1596
+ emailStore.setState({
1597
+ prependEmails: []
1637
1598
  });
1599
+ actions3.clearAttachments();
1638
1600
  },
1639
- async setTablePrependData(response, props) {
1640
- const state = tableStore2.getState();
1641
- const formState = formStore.getState();
1642
- let rows = [];
1643
- if (state.tableData?.info?.viewType == "BOARD") {
1644
- if (response === "loading") {
1645
- const responseData = state.tableData?.data?.results ?? [];
1646
- const pipelineStage = props?.payload?.propertyPayload?.hs_pipeline_stage || props?.payload?.propertyPayload?.dealstage || formState?.form?.data?.pipelineDefaults?.defaultStage?.id;
1647
- rows = responseData.map(
1648
- ({ id, data }) => {
1649
- const matchedPrepend = state.tablePrependData.find(
1650
- (item) => String(item.id) === String(id)
1651
- );
1652
- const prependRows = matchedPrepend?.data?.results?.rows ?? [];
1653
- const newRow = String(id) === String(pipelineStage) ? [
1654
- (data?.results?.columns ?? []).reduce(
1655
- (obj, column) => {
1656
- obj[column.key] = "loading";
1657
- return obj;
1658
- },
1659
- {}
1601
+ async updatePrependEmail(response) {
1602
+ const responseData = { ...response };
1603
+ const state = emailStore.getState();
1604
+ const prependEmails = state.prependEmails || [];
1605
+ const email = response.data || null;
1606
+ const storedAttachments = uploaderStore.getState().attachments;
1607
+ const emails = prependEmails.map(
1608
+ (item) => item?.hs_object_id === email?.hs_object_id?.value ? {
1609
+ ...item,
1610
+ ...Object.fromEntries(
1611
+ Object.entries(email).map(([key, value]) => {
1612
+ if (key === "hs_attachment_ids") {
1613
+ return [
1614
+ key,
1615
+ resolveAttachmentsFromIds(value, storedAttachments)
1616
+ ];
1617
+ }
1618
+ return [key, value?.value ?? value];
1619
+ })
1620
+ )
1621
+ } : item
1622
+ );
1623
+ emailStore.setState({
1624
+ prependEmails: emails
1625
+ });
1626
+ if (responseData?.data?.hs_attachment_ids != null) {
1627
+ const emailObjectId = email?.hs_object_id?.value;
1628
+ const rows = state.emails?.data?.results?.rows ?? [];
1629
+ const matchingRow = rows.find(
1630
+ (row) => String(row.hs_object_id) === String(emailObjectId)
1631
+ );
1632
+ const originalPrependItem = prependEmails.find(
1633
+ (item) => String(item?.hs_object_id) === String(emailObjectId)
1634
+ );
1635
+ const existingAttachments = matchingRow?.hs_attachment_ids ?? originalPrependItem?.hs_attachment_ids ?? [];
1636
+ const newAttachments = resolveAttachmentsFromIds(
1637
+ responseData.data.hs_attachment_ids,
1638
+ storedAttachments
1639
+ );
1640
+ const mergedAttachments = [
1641
+ ...existingAttachments,
1642
+ ...newAttachments.filter(
1643
+ (attachment) => !existingAttachments.some(
1644
+ (existing) => String(existing.id) === String(attachment.id)
1645
+ )
1646
+ )
1647
+ ];
1648
+ const stateUpdates = {};
1649
+ if (matchingRow && state.emails?.data?.results) {
1650
+ stateUpdates.emails = {
1651
+ ...state.emails,
1652
+ data: {
1653
+ ...state.emails.data,
1654
+ results: {
1655
+ ...state.emails.data.results,
1656
+ rows: rows.map(
1657
+ (row) => String(row.hs_object_id) === String(emailObjectId) ? { ...row, hs_attachment_ids: mergedAttachments } : row
1660
1658
  )
1661
- ] : [];
1662
- return {
1663
- id,
1664
- data: {
1665
- results: {
1666
- columns: data?.results?.columns ?? [],
1667
- // prepend loading row + prepend rows
1668
- rows: [
1669
- ...newRow,
1670
- ...prependRows
1671
- ]
1672
- }
1673
- }
1674
- };
1659
+ }
1675
1660
  }
1661
+ };
1662
+ }
1663
+ if (originalPrependItem) {
1664
+ stateUpdates.prependEmails = prependEmails.map(
1665
+ (item) => String(item?.hs_object_id) === String(emailObjectId) ? { ...item, hs_attachment_ids: mergedAttachments } : item
1676
1666
  );
1677
- } else {
1678
- const data = response?.data;
1679
- const hs_pipeline_stage = data?.hs_pipeline_stage?.value?.value || data?.dealstage?.value?.value;
1680
- if (!data) {
1681
- tableStore2.setState({
1682
- tablePrependData: []
1683
- });
1684
- }
1685
- rows = state?.tablePrependData.map((row) => {
1686
- const matchedPrepend = state.tablePrependData.find(
1687
- (item) => String(item.id) === String(row.id)
1688
- );
1689
- const prependRows = matchedPrepend?.data?.results?.rows ?? [];
1690
- if (String(row.id) === String(hs_pipeline_stage)) {
1691
- const updatedRow = (row?.data?.results?.columns ?? []).reduce(
1692
- (obj, column) => {
1693
- const key = column.key;
1694
- obj[key] = data?.[key]?.value ?? data?.[key] ?? "";
1695
- return obj;
1696
- },
1697
- {}
1698
- );
1699
- prependRows[0] = updatedRow;
1700
- return {
1701
- ...row,
1702
- data: {
1703
- ...row.data,
1704
- results: {
1705
- ...row.data.results,
1706
- rows: prependRows
1707
- }
1708
- }
1709
- };
1710
- }
1711
- return row;
1712
- });
1713
1667
  }
1714
- } else if (state.tableData?.info?.viewType == "LIST") {
1715
- if (response === "loading") {
1716
- const row = await state.tableData?.data?.results?.columns.reduce((acc, item) => {
1717
- if (!item.hidden) {
1718
- acc[item.key] = "loading";
1719
- }
1720
- return acc;
1721
- }, {});
1722
- rows = [row, ...state.tablePrependData];
1723
- } else if (response?.data) {
1724
- const data = response?.data;
1725
- if (!data) {
1726
- tableStore2.setState({
1727
- tablePrependData: []
1728
- });
1668
+ if (Object.keys(stateUpdates).length > 0) {
1669
+ emailStore.setState(stateUpdates);
1670
+ }
1671
+ responseData.data.hs_attachment_ids = mergedAttachments;
1672
+ }
1673
+ return responseData;
1674
+ }
1675
+ };
1676
+
1677
+ // src/store2/use-file.ts
1678
+ var fileStore = createStore2({
1679
+ queryParams: null
1680
+ });
1681
+ var actions6 = {
1682
+ /** Called from Client.file.list — feeds purgeEngagementCaches (view: files). */
1683
+ setListQueryParams(params) {
1684
+ fileStore.setState({
1685
+ queryParams: params
1686
+ });
1687
+ }
1688
+ };
1689
+
1690
+ // src/utils/cache/builders.ts
1691
+ function buildCrmListPurgeTarget(objectTypeId, listQuery) {
1692
+ return {
1693
+ domain: "crm_object_data",
1694
+ objectTypeId,
1695
+ views: ["list"],
1696
+ listQuery: listQuery ?? { page: 1, limit: 10, view: "LIST" }
1697
+ };
1698
+ }
1699
+ function buildCrmSinglePurgeTarget(objectTypeId, recordIds, listQuery) {
1700
+ return {
1701
+ domain: "crm_object_data",
1702
+ objectTypeId,
1703
+ views: ["single"],
1704
+ recordIds,
1705
+ listQuery
1706
+ };
1707
+ }
1708
+ function buildEngagementPurgeTarget(objectTypeId, recordIds, views, options) {
1709
+ if (!recordIds.length) {
1710
+ throw new Error("recordIds is required for engagement purge views");
1711
+ }
1712
+ return {
1713
+ domain: "crm_object_data",
1714
+ objectTypeId,
1715
+ recordIds,
1716
+ views,
1717
+ fileIds: options?.fileIds,
1718
+ listQuery: options?.listQuery ?? { page: 1, limit: 10 }
1719
+ };
1720
+ }
1721
+ function buildUserSessionPurgeTarget() {
1722
+ return { domain: "user_session" };
1723
+ }
1724
+ function buildPortalConfigPurgeTarget(objectTypeIds) {
1725
+ return {
1726
+ domain: "portal_object_config",
1727
+ objectTypeIds
1728
+ };
1729
+ }
1730
+ function mergePurgeTargets(...targets) {
1731
+ return targets;
1732
+ }
1733
+ function buildCachePurgeRequest(targets, options) {
1734
+ return {
1735
+ mode: options?.mode ?? "soft",
1736
+ warm: options?.warm ?? true,
1737
+ includeContactAccess: options?.includeContactAccess ?? true,
1738
+ includeShortOnHard: options?.includeShortOnHard ?? false,
1739
+ confirmPortalWide: options?.confirmPortalWide ?? false,
1740
+ targets
1741
+ };
1742
+ }
1743
+
1744
+ // src/utils/cache/createCachePurgeJob.ts
1745
+ function randomIdempotencyKey() {
1746
+ if (typeof crypto !== "undefined" && crypto.randomUUID) {
1747
+ return crypto.randomUUID();
1748
+ }
1749
+ return `purge-${Date.now()}-${Math.random().toString(36).slice(2)}`;
1750
+ }
1751
+ function mapErrorCode(status, message) {
1752
+ if (status === 400 || status === 422) {
1753
+ return "VALIDATION";
1754
+ }
1755
+ if (status === 429) {
1756
+ return "RATE_LIMITED";
1757
+ }
1758
+ if (message?.toLowerCase().includes("disabled")) {
1759
+ return "PURGE_API_DISABLED";
1760
+ }
1761
+ return status ? "UNKNOWN" : "NETWORK";
1762
+ }
1763
+ function sleep(ms) {
1764
+ return new Promise((resolve) => setTimeout(resolve, ms));
1765
+ }
1766
+ async function createCachePurgeJob(request, options = {}) {
1767
+ const idempotencyKey = options.idempotencyKey ?? randomIdempotencyKey();
1768
+ try {
1769
+ const headers = { "Idempotency-Key": idempotencyKey };
1770
+ const response = await Client.cache.purge(
1771
+ request,
1772
+ headers
1773
+ );
1774
+ const data = response?.data;
1775
+ const purgeJobId = data?.purgeJobId;
1776
+ let status = data?.status;
1777
+ if (options.waitForWarm && purgeJobId && request.warm !== false) {
1778
+ const timeout = options.pollTimeoutMs ?? 3e4;
1779
+ const interval = options.pollIntervalMs ?? 500;
1780
+ const deadline = Date.now() + timeout;
1781
+ while (Date.now() < deadline) {
1782
+ const statusRes = await Client.cache.purgeStatus(purgeJobId);
1783
+ const job = statusRes?.data;
1784
+ const jobStatus = job?.status;
1785
+ if (jobStatus === "completed") {
1786
+ status = "completed";
1787
+ break;
1729
1788
  }
1730
- const row = await Object.fromEntries(
1731
- Object.entries(data).map(([key, value]) => [
1732
- key,
1733
- value?.value ?? value
1734
- ])
1735
- );
1736
- rows = [...state.tablePrependData];
1737
- if (rows.length > 0) {
1738
- rows[0] = row;
1739
- } else {
1740
- rows.push(row);
1789
+ if (jobStatus === "failed") {
1790
+ return {
1791
+ ok: false,
1792
+ purgeJobId,
1793
+ status: "failed",
1794
+ errorCode: "WARM_FAILED",
1795
+ message: "Cache warm job failed"
1796
+ };
1741
1797
  }
1798
+ await sleep(interval);
1799
+ }
1800
+ if (status !== "completed") {
1801
+ return {
1802
+ ok: false,
1803
+ purgeJobId,
1804
+ status: status ?? "warming",
1805
+ errorCode: "WARM_FAILED",
1806
+ message: "Timed out waiting for cache warm job"
1807
+ };
1742
1808
  }
1743
1809
  }
1744
- tableStore2.setState({
1745
- tablePrependData: rows
1746
- });
1810
+ return {
1811
+ ok: true,
1812
+ purgeJobId,
1813
+ status,
1814
+ evicted: data?.evicted,
1815
+ warnings: data?.warnings
1816
+ };
1817
+ } catch (err) {
1818
+ const axiosErr = err;
1819
+ const status = axiosErr.response?.status;
1820
+ const message = axiosErr.response?.data?.message ?? (err instanceof Error ? err.message : "Cache purge request failed");
1821
+ return {
1822
+ ok: false,
1823
+ errorCode: mapErrorCode(status, message),
1824
+ message
1825
+ };
1826
+ }
1827
+ }
1828
+
1829
+ // src/utils/cache/crmCacheRefresh.ts
1830
+ async function purgeCrmObjectDataCache(options) {
1831
+ const result = await purgeCrmListCache(options);
1832
+ return result.ok;
1833
+ }
1834
+ async function purgeCrmListCache(options) {
1835
+ const objectTypeId = options.objectTypeId?.trim();
1836
+ if (!objectTypeId) {
1837
+ return { ok: false, errorCode: "VALIDATION", message: "objectTypeId is required" };
1747
1838
  }
1748
- };
1749
-
1750
- // src/store2/use-uploader.ts
1751
- var uploaderStore = createStore2({
1752
- attachments: []
1753
- });
1754
- function toAttachmentSummary(attachment) {
1755
- return {
1756
- createdAt: attachment.createdAt,
1757
- id: attachment.id,
1758
- name: attachment.name,
1759
- size: attachment.size,
1760
- type: attachment.type,
1761
- updatedAt: attachment.updatedAt
1762
- };
1839
+ const target = buildCrmListPurgeTarget(objectTypeId, options.listQuery);
1840
+ const request = buildCachePurgeRequest([target], {
1841
+ mode: options.mode,
1842
+ warm: options.warm
1843
+ });
1844
+ return createCachePurgeJob(request, {
1845
+ idempotencyKey: options.idempotencyKey,
1846
+ waitForWarm: options.waitForWarm
1847
+ });
1763
1848
  }
1764
- function resolveAttachmentsFromIds(attachmentIds, storedAttachments) {
1765
- const raw = typeof attachmentIds === "object" && attachmentIds !== null && "value" in attachmentIds ? attachmentIds.value : attachmentIds;
1766
- const ids = String(raw ?? "").split(";").map((id) => id.trim()).filter(Boolean);
1767
- return ids.map((id) => storedAttachments.find((a) => String(a.id) === id)).filter((a) => a != null).map(toAttachmentSummary);
1849
+ async function purgeCrmRecordCache(options) {
1850
+ const objectTypeId = options.objectTypeId?.trim();
1851
+ if (!objectTypeId || !options.recordIds?.length) {
1852
+ return {
1853
+ ok: false,
1854
+ errorCode: "VALIDATION",
1855
+ message: "objectTypeId and recordIds are required"
1856
+ };
1857
+ }
1858
+ const target = buildCrmSinglePurgeTarget(
1859
+ objectTypeId,
1860
+ options.recordIds,
1861
+ options.listQuery
1862
+ );
1863
+ const request = buildCachePurgeRequest([target], {
1864
+ mode: options.mode,
1865
+ warm: options.warm
1866
+ });
1867
+ return createCachePurgeJob(request, {
1868
+ idempotencyKey: options.idempotencyKey,
1869
+ waitForWarm: options.waitForWarm
1870
+ });
1768
1871
  }
1769
- var actions3 = {
1770
- setAttachment(response) {
1771
- const data = response?.data;
1772
- if (!data?.id) return;
1773
- const state = uploaderStore.getState();
1774
- const id = String(data.id);
1775
- const existing = state.attachments;
1776
- const index = existing.findIndex((item) => String(item.id) === id);
1777
- const attachments = index >= 0 ? existing.map((item, i) => i === index ? data : item) : [...existing, data];
1778
- uploaderStore.setState({ attachments });
1779
- },
1780
- clearAttachments() {
1781
- uploaderStore.setState({ attachments: [] });
1872
+ async function purgeEngagementCaches(options) {
1873
+ const objectTypeId = options.objectTypeId?.trim();
1874
+ if (!objectTypeId || !options.recordIds?.length || !options.views?.length) {
1875
+ return {
1876
+ ok: false,
1877
+ errorCode: "VALIDATION",
1878
+ message: "objectTypeId, recordIds, and views are required"
1879
+ };
1782
1880
  }
1783
- };
1881
+ const target = buildEngagementPurgeTarget(
1882
+ objectTypeId,
1883
+ options.recordIds,
1884
+ options.views,
1885
+ { fileIds: options.fileIds, listQuery: options.listQuery }
1886
+ );
1887
+ const request = buildCachePurgeRequest([target], {
1888
+ mode: options.mode,
1889
+ warm: options.warm
1890
+ });
1891
+ return createCachePurgeJob(request, {
1892
+ idempotencyKey: options.idempotencyKey,
1893
+ waitForWarm: options.waitForWarm
1894
+ });
1895
+ }
1896
+ async function purgeCrmCombined(options) {
1897
+ const request = buildCachePurgeRequest(options.targets, {
1898
+ mode: options.mode,
1899
+ warm: options.warm
1900
+ });
1901
+ return createCachePurgeJob(request, {
1902
+ idempotencyKey: options.idempotencyKey,
1903
+ waitForWarm: options.waitForWarm
1904
+ });
1905
+ }
1784
1906
 
1785
- // src/store2/use-note.ts
1786
- var noteStore = createStore2({
1787
- notes: [],
1788
- prependNotes: [],
1789
- id: ""
1790
- });
1791
- var actions4 = {
1792
- setNotes(response, payload) {
1793
- const state = noteStore.getState();
1794
- const rows = response?.data?.results?.rows ?? [];
1795
- const rowIds = new Set(
1796
- rows.map((row) => row.id ?? row.hs_object_id).filter((id2) => id2 != null && id2 !== "").map((id2) => String(id2))
1797
- );
1798
- let newPrependNotes = state.prependNotes.filter((item) => {
1799
- const itemId = item.id ?? item.hs_object_id;
1800
- if (itemId == null || itemId === "") return true;
1801
- return !rowIds.has(String(itemId));
1802
- });
1803
- const id = payload?.params?.id;
1804
- if (state.id && state.id != id) {
1805
- newPrependNotes = [];
1907
+ // src/client/index.ts
1908
+ var recordWriteContext = (paramsObject) => {
1909
+ if (!paramsObject) {
1910
+ return void 0;
1911
+ }
1912
+ const context = {};
1913
+ const keys = [
1914
+ "parentObjectTypeId",
1915
+ "parentObjectRecordId",
1916
+ "mediatorObjectTypeId",
1917
+ "mediatorObjectRecordId"
1918
+ ];
1919
+ keys.forEach((key) => {
1920
+ const value = paramsObject[key];
1921
+ if (value !== void 0 && value !== null && String(value).length > 0) {
1922
+ context[key] = String(value);
1806
1923
  }
1807
- noteStore.setState({
1808
- notes: response,
1809
- prependNotes: newPrependNotes,
1810
- id
1811
- });
1812
- },
1813
- async setPrependNote(response) {
1814
- const state = noteStore.getState();
1815
- let rows = [];
1816
- if (response === "loading") {
1817
- const row = await state.notes?.data?.results?.columns.reduce((acc, item) => {
1818
- if (!item.hidden) {
1819
- acc[item.key] = "loading";
1924
+ });
1925
+ return Object.keys(context).length > 0 ? context : void 0;
1926
+ };
1927
+ var mergeRecordWriteBody = (payload, paramsObject, options) => {
1928
+ const base = { ...payload || {} };
1929
+ const context = recordWriteContext(paramsObject);
1930
+ if (context) {
1931
+ base.context = context;
1932
+ }
1933
+ if (options && Object.keys(options).length > 0) {
1934
+ base.options = options;
1935
+ }
1936
+ return base;
1937
+ };
1938
+ var Client = {
1939
+ authentication: {
1940
+ preLogin: (data) => AuthHttpClient.post(API_ENDPOINTS.PRE_LOGIN, data),
1941
+ login: (data) => {
1942
+ const queryParams = config.hubId ? { hubId: config.hubId } : null;
1943
+ return AuthHttpClient.post(
1944
+ generateApiUrl({ route: API_ENDPOINTS.LOGIN, queryParams }),
1945
+ data,
1946
+ config?.devPortalId && {
1947
+ headers: {
1948
+ "X-Dev-Portal-Id": config.devPortalId
1949
+ }
1820
1950
  }
1821
- return acc;
1822
- }, {});
1823
- rows = [row, ...state.prependNotes];
1824
- } else if (response?.data) {
1825
- const data = response?.data;
1826
- if (!data) {
1827
- noteStore.setState({
1828
- prependNotes: []
1951
+ );
1952
+ },
1953
+ verifyEmail: (data) => AuthHttpClient.post(API_ENDPOINTS.VERIFY_EMAIL, data),
1954
+ resetPasswordVerifyToken: (data) => AuthHttpClient.post(API_ENDPOINTS.RESET_PASSWORD_VERIFY_TOKEN, data),
1955
+ resetPassword: (data) => AuthHttpClient.post(API_ENDPOINTS.RESET_PASSWORD, data),
1956
+ forgetPassword: (data) => AuthHttpClient.post(API_ENDPOINTS.FORGET_PASSWORD, data),
1957
+ registerExistingUser: (data) => AuthHttpClient.post(API_ENDPOINTS.REGISTER_EXISTING_USER, data?.payload),
1958
+ verifyEmailResend: (data) => AuthHttpClient.post(API_ENDPOINTS.VERIFY_EMAIL_RESEND, data),
1959
+ resendEmail: (data) => AuthHttpClient.post(API_ENDPOINTS.RESEND_EMAIL, data),
1960
+ logout: () => HttpClient.post(API_ENDPOINTS.LOGOUT, null)
1961
+ },
1962
+ sso: {
1963
+ getSsoDetails: () => AuthHttpClient.get(API_ENDPOINTS.SSO_DETAILS),
1964
+ generateSsoUrl: (payload) => AuthHttpClient.get(generateApiUrl({ route: API_ENDPOINTS.SSO_URL, queryParams: payload?.queryParams })),
1965
+ ssoCallback: (payload) => AuthHttpClient.get(generateApiUrl({ route: API_ENDPOINTS.SSO_CALLBACK, queryParams: payload?.queryParams }))
1966
+ },
1967
+ user: {
1968
+ me: () => HttpClient.get(generateApiUrl({ route: API_ENDPOINTS.ME })),
1969
+ profile: (payload) => HttpClient.get(generateApiUrl({ route: API_ENDPOINTS.PROFILE, queryParams: payload })),
1970
+ changePassword: (data) => HttpClient.post(API_ENDPOINTS.CHANGE_PASSWORD, data)
1971
+ },
1972
+ pipeline: {
1973
+ list: (payload = null, param = null) => {
1974
+ const params = { hubspotObjectTypeId: payload?.hubspotObjectTypeId };
1975
+ const { getParamDetails: getParamDetails2 } = routeParam;
1976
+ const { paramsObject } = getParamDetails2({ type: payload?.componentName });
1977
+ const userData = getProfileData();
1978
+ const apiParams = {};
1979
+ if (paramsObject?.parentObjectTypeId) {
1980
+ apiParams.parentObjectTypeId = paramsObject?.parentObjectTypeId;
1981
+ } else if (payload?.isHome && userData?.data?.info?.objectTypeId && !param?.isPrimaryCompany) {
1982
+ apiParams.parentObjectTypeId = userData?.data?.info?.objectTypeId;
1983
+ } else if (payload?.isHome && userData?.data?.info?.objectTypeId && param?.isPrimaryCompany) {
1984
+ apiParams.parentObjectTypeId = "0-2";
1985
+ }
1986
+ apiParams.isPrimaryCompany = param?.isPrimaryCompany;
1987
+ apiParams.cache = payload?.cache;
1988
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.PIPELINES, params, queryParams: apiParams });
1989
+ return HttpClient.get(apiUrl);
1990
+ }
1991
+ },
1992
+ stage: {
1993
+ list: (props = null) => {
1994
+ const params = {
1995
+ // hubId: config.hubId,
1996
+ // portalId: portalId,
1997
+ objectTypeId: props?.params?.objectTypeId,
1998
+ pipelineId: props?.params?.pipelineId
1999
+ };
2000
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.STAGES, params });
2001
+ return HttpClient.get(apiUrl);
2002
+ }
2003
+ },
2004
+ object: {
2005
+ list: async (payload = null, param = null) => {
2006
+ const { setObjectsQueryParams } = actions2;
2007
+ param.cache = payload?.cache !== false ? true : false;
2008
+ const params = { hubspotObjectTypeId: payload?.hubspotObjectTypeId };
2009
+ const { updateLink, getLinkParams } = useUpdateLink();
2010
+ const { getParamDetails: getParamDetails2 } = routeParam;
2011
+ const { paramsObject, parentAccessLabel } = getParamDetails2({ type: payload?.componentName });
2012
+ const userData = getProfileData();
2013
+ const pipeline = payload?.variables?.pipeline;
2014
+ const mPipelines = payload?.variables?.mPipelines;
2015
+ const mSelectedPipeline = pipeline !== void 0 ? pipeline : payload?.selectedPipeline;
2016
+ if (mSelectedPipeline) {
2017
+ param.filterValue = mSelectedPipeline;
2018
+ } else if (payload?.specPipeLine && payload?.pipeLineId) {
2019
+ param.filterValue = payload?.pipeLineId;
2020
+ } else if (payload?.hubspotObjectTypeId != "0-3" || payload?.hubspotObjectTypeId != "0-5") {
2021
+ param.filterValue = "";
2022
+ }
2023
+ const fParams = getLinkParams();
2024
+ param = { ...payload?.isFristTimeLoadData && fParams && !payload?.isHome ? fParams : param, ...paramsObject };
2025
+ if (!payload?.isFristTimeLoadData || !fParams) {
2026
+ await updateLink({
2027
+ "sort": param?.sort,
2028
+ "s": param?.search,
2029
+ "fPn": param?.filterPropertyName,
2030
+ "fO": param?.filterOperator,
2031
+ "fV": param?.filterValue,
2032
+ "c": param?.cache !== false,
2033
+ "isPC": param?.isPrimaryCompany,
2034
+ "v": param?.view,
2035
+ "l": param?.limit,
2036
+ "p": param?.page,
2037
+ "a": param?.after
1829
2038
  });
1830
2039
  }
1831
- const storedAttachments = uploaderStore.getState().attachments;
1832
- const row = Object.fromEntries(
1833
- Object.entries(data).map(([key, value]) => {
1834
- if (key === "hs_attachment_ids") {
1835
- return [
1836
- key,
1837
- resolveAttachmentsFromIds(value, storedAttachments)
1838
- ];
1839
- }
1840
- return [key, value?.value ?? value];
1841
- })
2040
+ if (mPipelines != void 0 && mPipelines?.length === 0 && !payload?.specPipeLine) {
2041
+ param.filterValue = "";
2042
+ await updateLink({
2043
+ "fV": param?.filterValue
2044
+ });
2045
+ }
2046
+ if (mPipelines != void 0 && mPipelines?.length === 1 && !payload?.specPipeLine && mSelectedPipeline != null) {
2047
+ param.filterValue = mPipelines[0].pipelineId;
2048
+ await updateLink({
2049
+ "fV": param?.filterValue
2050
+ });
2051
+ }
2052
+ if (payload?.isHome || payload?.hubspotObjectTypeId === "0-5" && payload?.componentName === "object") {
2053
+ let parentObjectTypeId = "";
2054
+ if (userData?.data?.info?.objectTypeId && !param?.isPrimaryCompany) {
2055
+ parentObjectTypeId = userData?.data?.info?.objectTypeId;
2056
+ } else if (userData?.data?.info?.objectTypeId && param?.isPrimaryCompany) {
2057
+ parentObjectTypeId = "0-2";
2058
+ }
2059
+ param.parentObjectTypeId = parentObjectTypeId;
2060
+ }
2061
+ param.parentAccessLabel = parentAccessLabel;
2062
+ const {
2063
+ stageId,
2064
+ nextPage
2065
+ } = useTable();
2066
+ if (stageId) {
2067
+ param.stageId = stageId;
2068
+ }
2069
+ if (param?.view === "BOARD") {
2070
+ param.page = nextPage;
2071
+ }
2072
+ setObjectsQueryParams(param);
2073
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.OBJECTS, params, queryParams: param });
2074
+ return HttpClient.get(apiUrl);
2075
+ },
2076
+ sideBarList: async (payload = null) => {
2077
+ const { setMultiObjectsQueryParams } = actions2;
2078
+ const hubspotObjectTypeId = payload?.hubspotObjectTypeId;
2079
+ const params = { hubspotObjectTypeId };
2080
+ const queryParams = payload.param;
2081
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.OBJECTS, params, queryParams });
2082
+ setMultiObjectsQueryParams(hubspotObjectTypeId, queryParams ?? {});
2083
+ return HttpClient.get(apiUrl);
2084
+ },
2085
+ form: (payload = null) => {
2086
+ const params = { hubspotObjectTypeId: payload?.hubspotObjectTypeId };
2087
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.OBJECTS_FORM, params, queryParams: payload?.params });
2088
+ return HttpClient.get(apiUrl);
2089
+ },
2090
+ objectFormOptions: (payload = null) => {
2091
+ const params = {
2092
+ formId: payload?.formId,
2093
+ objectTypeId: payload?.objectTypeId ?? payload?.hubspotObjectTypeId
2094
+ };
2095
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.OBJECTS_FORM_OPTIONS, params, queryParams: payload?.params });
2096
+ return HttpClient.get(apiUrl);
2097
+ },
2098
+ create: async (props = null) => {
2099
+ const { getParamDetails: getParamDetailsForCreate } = routeParam;
2100
+ const { paramsObject } = getParamDetailsForCreate({ type: props?.componentName });
2101
+ const cardParentMerge = props?.componentName === "association" ? true : false;
2102
+ const body = mergeRecordWriteBody(props?.payload, paramsObject, {
2103
+ cardParentMerge,
2104
+ addAnother: props?.params?.addAnother
2105
+ });
2106
+ const params = { hubspotObjectTypeId: props?.hubspotObjectTypeId };
2107
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.RECORDS_CREATE, params, queryParams: props?.params });
2108
+ const response = await HttpClient.post(apiUrl, body);
2109
+ const { queryParams, multiObjectsQueryParams } = tableStore2.getState();
2110
+ const listQuery = props?.componentName === "association" ? {} : props?.componentName === "sidebarTable" ? multiObjectsQueryParams?.[String(props?.hubspotObjectTypeId)] ?? {} : queryParams ?? {};
2111
+ const objectTypeId = props?.hubspotObjectTypeId;
2112
+ if (objectTypeId) {
2113
+ purgeCrmListCache({ objectTypeId, listQuery });
2114
+ }
2115
+ return response;
2116
+ },
2117
+ createExisting: (props = null) => {
2118
+ const { getLinkParams } = useUpdateLink();
2119
+ const fParams = getLinkParams();
2120
+ const queryParams = { ...fParams, ...props?.params };
2121
+ const params = {
2122
+ fromObjectTypeId: props?.fromObjectTypeId ?? props?.hubspotObjectTypeId,
2123
+ fromRecordId: props?.fromRecordId,
2124
+ toObjectTypeId: props?.toObjectTypeId
2125
+ };
2126
+ const payload = props.payload;
2127
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.RECORDS_ASSOCIATE, params, queryParams });
2128
+ return HttpClient.post(apiUrl, payload);
2129
+ },
2130
+ removeExisting: (props = null) => {
2131
+ const { getParamDetails: getParamDetailsForRemove } = routeParam;
2132
+ const { paramsObject } = getParamDetailsForRemove({ type: props?.componentName });
2133
+ const body = mergeRecordWriteBody(props?.payload, paramsObject, void 0);
2134
+ const params = {
2135
+ fromObjectTypeId: props?.fromObjectTypeId ?? props?.hubspotObjectTypeId,
2136
+ fromRecordId: props?.fromRecordId,
2137
+ toObjectTypeId: props?.toObjectTypeId
2138
+ };
2139
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.RECORDS_DISASSOCIATE, params });
2140
+ return HttpClient.delete(apiUrl, { data: body });
2141
+ },
2142
+ details: (props = null) => {
2143
+ const { paramsObject: urlParam, parentAccessLabel } = getParamDetails("", true);
2144
+ const hubspotObjectTypeId = ticketHubspotObjectTypeId();
2145
+ const params = {
2146
+ // hubId: config.hubId,
2147
+ // portalId: portalId,
2148
+ objectId: props?.params?.objectId,
2149
+ id: props?.params?.id
2150
+ };
2151
+ const queryParams = {
2152
+ parentAccessLabel,
2153
+ ...props?.queryParams,
2154
+ ...urlParam
2155
+ };
2156
+ if (hubspotObjectTypeId) queryParams.parentObjectTypeId = hubspotObjectTypeId;
2157
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.OBJECTS_DETAILS, params, queryParams });
2158
+ return HttpClient.get(apiUrl);
2159
+ },
2160
+ update: async (props = null) => {
2161
+ const hubspotObjectTypeId = ticketHubspotObjectTypeId();
2162
+ const params = {
2163
+ objectId: props?.params?.objectId,
2164
+ id: props?.params?.id
2165
+ };
2166
+ const { getParamDetails: getParamDetailsForUpdate } = routeParam;
2167
+ const { paramsObject } = getParamDetailsForUpdate({ type: props?.componentName });
2168
+ const cardParentMerge = props?.componentName === "association" ? true : false;
2169
+ const rawPayload = props?.payload || {};
2170
+ const properties = rawPayload.properties ?? rawPayload.propertyPayload ?? rawPayload;
2171
+ const body = mergeRecordWriteBody(
2172
+ { properties },
2173
+ paramsObject,
2174
+ { cardParentMerge }
1842
2175
  );
1843
- rows = [...state.prependNotes];
1844
- if (rows.length > 0) {
1845
- rows[0] = row;
1846
- } else {
1847
- rows.push(row);
2176
+ const queryParams = {};
2177
+ if (hubspotObjectTypeId) queryParams.parentObjectTypeId = hubspotObjectTypeId;
2178
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.RECORDS_UPDATE, params, queryParams });
2179
+ const { queryParams: tableQueryParams, multiObjectsQueryParams } = tableStore2.getState();
2180
+ const listQuery = props?.componentName === "sidebarTable" ? multiObjectsQueryParams?.[String(props?.hubspotObjectTypeId)] ?? {} : tableQueryParams ?? {};
2181
+ const response = await HttpClient.put(apiUrl, body);
2182
+ const objectTypeId = props?.hubspotObjectTypeId ?? props?.params?.objectId;
2183
+ const recordId = props?.params?.id;
2184
+ if (objectTypeId && recordId) {
2185
+ purgeCrmRecordCache({
2186
+ objectTypeId: String(objectTypeId),
2187
+ recordIds: [String(recordId)],
2188
+ listQuery
2189
+ });
2190
+ } else if (objectTypeId) {
2191
+ purgeCrmListCache({ objectTypeId: String(objectTypeId), listQuery });
1848
2192
  }
2193
+ return response;
1849
2194
  }
1850
- noteStore.setState({
1851
- prependNotes: rows
1852
- });
1853
- },
1854
- clearPrependNotes() {
1855
- noteStore.setState({
1856
- prependNotes: []
1857
- });
1858
- actions3.clearAttachments();
1859
2195
  },
1860
- async updatePrependNote(response) {
1861
- const responseData = { ...response };
1862
- const state = noteStore.getState();
1863
- const prependNotes = state.prependNotes || [];
1864
- const note = response.data || null;
1865
- const storedAttachments = uploaderStore.getState().attachments;
1866
- const notes = prependNotes.map(
1867
- (item) => item?.hs_object_id === note?.hs_object_id?.value ? {
1868
- ...item,
1869
- ...Object.fromEntries(
1870
- Object.entries(note).map(([key, value]) => {
1871
- if (key === "hs_attachment_ids") {
1872
- return [
1873
- key,
1874
- resolveAttachmentsFromIds(value, storedAttachments)
1875
- ];
1876
- }
1877
- return [key, value?.value ?? value];
1878
- })
1879
- )
1880
- } : item
1881
- );
1882
- noteStore.setState({
1883
- prependNotes: notes
1884
- });
1885
- if (responseData?.data?.hs_attachment_ids != null) {
1886
- const noteObjectId = note?.hs_object_id?.value;
1887
- const rows = state.notes?.data?.results?.rows ?? [];
1888
- const matchingRow = rows.find(
1889
- (row) => String(row.hs_object_id) === String(noteObjectId)
1890
- );
1891
- const originalPrependItem = prependNotes.find(
1892
- (item) => String(item?.hs_object_id) === String(noteObjectId)
1893
- );
1894
- const existingAttachments = matchingRow?.hs_attachment_ids ?? originalPrependItem?.hs_attachment_ids ?? [];
1895
- const newAttachments = resolveAttachmentsFromIds(
1896
- responseData.data.hs_attachment_ids,
1897
- storedAttachments
1898
- );
1899
- const mergedAttachments = [
1900
- ...existingAttachments,
1901
- ...newAttachments.filter(
1902
- (attachment) => !existingAttachments.some(
1903
- (existing) => String(existing.id) === String(attachment.id)
1904
- )
1905
- )
1906
- ];
1907
- const stateUpdates = {};
1908
- if (matchingRow && state.notes?.data?.results) {
1909
- stateUpdates.notes = {
1910
- ...state.notes,
1911
- data: {
1912
- ...state.notes.data,
1913
- results: {
1914
- ...state.notes.data.results,
1915
- rows: rows.map(
1916
- (row) => String(row.hs_object_id) === String(noteObjectId) ? { ...row, hs_attachment_ids: mergedAttachments } : row
1917
- )
1918
- }
1919
- }
1920
- };
1921
- }
1922
- if (originalPrependItem) {
1923
- stateUpdates.prependNotes = prependNotes.map(
1924
- (item) => String(item?.hs_object_id) === String(noteObjectId) ? { ...item, hs_attachment_ids: mergedAttachments } : item
1925
- );
2196
+ note: {
2197
+ list: (props = null) => {
2198
+ const { setListQueryParams } = actions4;
2199
+ setListQueryParams(props?.queryParams ?? {});
2200
+ const params = {
2201
+ // hubId: config.hubId,
2202
+ // portalId: portalId,
2203
+ objectId: props?.params?.objectId,
2204
+ id: props?.params?.id
2205
+ };
2206
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.NOTES, params, queryParams: props?.queryParams });
2207
+ return HttpClient.get(apiUrl);
2208
+ },
2209
+ create: async (props = null) => {
2210
+ const params = { hubspotObjectTypeId: props?.hubspotObjectTypeId, ...props.params };
2211
+ const queryParams = props.queryParams;
2212
+ const payload = props.payload;
2213
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.NOTES_CREATE, params, queryParams });
2214
+ const listQuery = noteStore.getState().queryParams ?? {};
2215
+ const response = await HttpClient.post(apiUrl, payload);
2216
+ const recordId = props?.params?.id;
2217
+ const objectTypeId = props?.params?.objectId;
2218
+ if (recordId && objectTypeId) {
2219
+ purgeEngagementCaches({
2220
+ objectTypeId,
2221
+ recordIds: [String(recordId)],
2222
+ views: ["notes"],
2223
+ listQuery
2224
+ });
1926
2225
  }
1927
- if (Object.keys(stateUpdates).length > 0) {
1928
- noteStore.setState(stateUpdates);
2226
+ return response;
2227
+ },
2228
+ update: async (props = null) => {
2229
+ const params = {
2230
+ // hubId: config.hubId,
2231
+ // portalId: portalId,
2232
+ objectId: props?.params?.objectId,
2233
+ id: props?.params?.id,
2234
+ note_id: props?.params?.note_id
2235
+ };
2236
+ const { paramsObject: queryParams } = getParamDetails();
2237
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.NOTES_DETAILS_UPDATE, params, queryParams });
2238
+ const listQuery = noteStore.getState().queryParams ?? {};
2239
+ const response = await HttpClient.put(apiUrl, props.payload);
2240
+ const recordId = props?.params?.id;
2241
+ const objectTypeId = props?.params?.objectId;
2242
+ if (recordId && objectTypeId) {
2243
+ purgeEngagementCaches({
2244
+ objectTypeId,
2245
+ recordIds: [String(recordId)],
2246
+ views: ["notes"],
2247
+ listQuery
2248
+ });
1929
2249
  }
1930
- responseData.data.hs_attachment_ids = mergedAttachments;
1931
- }
1932
- return responseData;
1933
- }
1934
- };
1935
-
1936
- // src/store2/use-email.ts
1937
- var emailStore = createStore2({
1938
- emails: [],
1939
- prependEmails: [],
1940
- id: ""
1941
- });
1942
- var actions5 = {
1943
- setEmails(response, payload) {
1944
- const state = emailStore.getState();
1945
- const rows = response?.data?.results?.rows ?? [];
1946
- const rowIds = new Set(
1947
- rows.map((row) => row.id ?? row.hs_object_id).filter((id2) => id2 != null && id2 !== "").map((id2) => String(id2))
1948
- );
1949
- let newPrependEmails = state.prependEmails.filter((item) => {
1950
- const itemId = item.id ?? item.hs_object_id;
1951
- if (itemId == null || itemId === "") return true;
1952
- return !rowIds.has(String(itemId));
1953
- });
1954
- const id = payload?.params?.id;
1955
- if (state.id && state.id != id) {
1956
- newPrependEmails = [];
2250
+ return response;
2251
+ },
2252
+ image: (props = null) => {
2253
+ const params = { hubspotObjectTypeId: props?.hubspotObjectTypeId, ...props.params };
2254
+ const queryParams = props.queryParams;
2255
+ const payload = props.payload;
2256
+ const axiosConfig = props.config || {};
2257
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.NOTES_IMAGE_UPLOAD, params, queryParams });
2258
+ return HttpClient.post(apiUrl, payload, {
2259
+ headers: {
2260
+ "Content-Type": "multipart/form-data"
2261
+ },
2262
+ ...axiosConfig
2263
+ });
2264
+ },
2265
+ attachment: (props = null) => {
2266
+ const params = { hubspotObjectTypeId: props?.hubspotObjectTypeId, ...props.params };
2267
+ const queryParams = props.queryParams;
2268
+ const payload = props.payload;
2269
+ const axiosConfig = props.config || {};
2270
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.NOTES_ATTACHMENT_UPLOAD, params, queryParams });
2271
+ return HttpClient.post(apiUrl, payload, {
2272
+ headers: {
2273
+ "Content-Type": "multipart/form-data"
2274
+ },
2275
+ ...axiosConfig
2276
+ });
1957
2277
  }
1958
- emailStore.setState({
1959
- emails: response,
1960
- prependEmails: newPrependEmails,
1961
- id
1962
- });
1963
2278
  },
1964
- async setPrependEmail(response) {
1965
- const state = emailStore.getState();
1966
- let rows = [];
1967
- if (response === "loading") {
1968
- const row = await state.emails?.data?.results?.columns.reduce((acc, item) => {
1969
- if (!item.hidden) {
1970
- acc[item.key] = "loading";
1971
- }
1972
- return acc;
1973
- }, {});
1974
- rows = [row, ...state.prependEmails];
1975
- } else if (response?.data) {
1976
- const data = response?.data;
1977
- if (!data) {
1978
- emailStore.setState({
1979
- prependEmails: []
2279
+ email: {
2280
+ list: (props = null) => {
2281
+ const { setListQueryParams } = actions5;
2282
+ setListQueryParams(props?.queryParams ?? {});
2283
+ const params = {
2284
+ // hubId: config.hubId,
2285
+ // portalId: portalId,
2286
+ objectId: props?.params?.objectId,
2287
+ id: props?.params?.id
2288
+ };
2289
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.EMAILS, params, queryParams: props?.queryParams });
2290
+ return HttpClient.get(apiUrl);
2291
+ },
2292
+ create: async (props = null) => {
2293
+ const params = { hubspotObjectTypeId: props?.hubspotObjectTypeId, ...props.params };
2294
+ const queryParams = props.queryParams;
2295
+ const payload = props.payload;
2296
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.EMAILS_CREATE, params, queryParams });
2297
+ const listQuery = emailStore.getState().queryParams ?? {};
2298
+ const response = await HttpClient.post(apiUrl, payload);
2299
+ const recordId = props?.params?.id;
2300
+ const objectTypeId = props?.params?.objectId;
2301
+ if (recordId && objectTypeId) {
2302
+ purgeEngagementCaches({
2303
+ objectTypeId,
2304
+ recordIds: [String(recordId)],
2305
+ views: ["emails"],
2306
+ listQuery
1980
2307
  });
1981
2308
  }
1982
- const storedAttachments = uploaderStore.getState().attachments;
1983
- const row = Object.fromEntries(
1984
- Object.entries(data).map(([key, value]) => {
1985
- if (key === "hs_attachment_ids") {
1986
- return [
1987
- key,
1988
- resolveAttachmentsFromIds(value, storedAttachments)
1989
- ];
1990
- }
1991
- return [key, value?.value ?? value];
1992
- })
1993
- );
1994
- rows = [...state.prependEmails];
1995
- if (rows.length > 0) {
1996
- rows[0] = row;
1997
- } else {
1998
- rows.push(row);
2309
+ return response;
2310
+ },
2311
+ update: async (props = null) => {
2312
+ const params = {
2313
+ // hubId: config.hubId,
2314
+ // portalId: portalId,
2315
+ objectId: props?.params?.objectId,
2316
+ id: props?.params?.id,
2317
+ email_id: props?.params?.email_id ?? props?.params?.note_id
2318
+ };
2319
+ const { paramsObject: queryParams } = getParamDetails();
2320
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.EMAILS_DETAILS_UPDATE, params, queryParams });
2321
+ const listQuery = emailStore.getState().queryParams ?? {};
2322
+ const response = await HttpClient.put(apiUrl, props.payload);
2323
+ const recordId = props?.params?.id;
2324
+ const objectTypeId = props?.params?.objectId;
2325
+ if (recordId && objectTypeId) {
2326
+ purgeEngagementCaches({
2327
+ objectTypeId,
2328
+ recordIds: [String(recordId)],
2329
+ views: ["emails"],
2330
+ listQuery
2331
+ });
1999
2332
  }
2333
+ return response;
2334
+ },
2335
+ image: (props = null) => {
2336
+ const params = { hubspotObjectTypeId: props?.hubspotObjectTypeId, ...props.params };
2337
+ const queryParams = props.queryParams;
2338
+ const payload = props.payload;
2339
+ const axiosConfig = props.config || {};
2340
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.EMAILS_IMAGE_UPLOAD, params, queryParams });
2341
+ return HttpClient.post(apiUrl, payload, {
2342
+ headers: {
2343
+ "Content-Type": "multipart/form-data"
2344
+ },
2345
+ ...axiosConfig
2346
+ });
2347
+ },
2348
+ attachment: (props = null) => {
2349
+ const params = { hubspotObjectTypeId: props?.hubspotObjectTypeId, ...props.params };
2350
+ const queryParams = props.queryParams;
2351
+ const payload = props.payload;
2352
+ const axiosConfig = props.config || {};
2353
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.EMAILS_ATTACHMENT_UPLOAD, params, queryParams });
2354
+ return HttpClient.post(apiUrl, payload, {
2355
+ headers: {
2356
+ "Content-Type": "multipart/form-data"
2357
+ },
2358
+ ...axiosConfig
2359
+ });
2000
2360
  }
2001
- emailStore.setState({
2002
- prependEmails: rows
2003
- });
2004
2361
  },
2005
- clearPrependEmails() {
2006
- emailStore.setState({
2007
- prependEmails: []
2008
- });
2009
- actions3.clearAttachments();
2362
+ cache: {
2363
+ purge: (body, headers) => {
2364
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.CACHE_PURGE });
2365
+ return HttpClient.post(apiUrl, body, headers ? { headers } : void 0);
2366
+ },
2367
+ purgeStatus: (purgeJobId) => {
2368
+ const apiUrl = generateApiUrl({
2369
+ route: API_ENDPOINTS.CACHE_PURGE_STATUS,
2370
+ params: { purgeJobId }
2371
+ });
2372
+ return HttpClient.get(apiUrl);
2373
+ }
2010
2374
  },
2011
- async updatePrependEmail(response) {
2012
- const responseData = { ...response };
2013
- const state = emailStore.getState();
2014
- const prependEmails = state.prependEmails || [];
2015
- const email = response.data || null;
2016
- const storedAttachments = uploaderStore.getState().attachments;
2017
- const emails = prependEmails.map(
2018
- (item) => item?.hs_object_id === email?.hs_object_id?.value ? {
2019
- ...item,
2020
- ...Object.fromEntries(
2021
- Object.entries(email).map(([key, value]) => {
2022
- if (key === "hs_attachment_ids") {
2023
- return [
2024
- key,
2025
- resolveAttachmentsFromIds(value, storedAttachments)
2026
- ];
2027
- }
2028
- return [key, value?.value ?? value];
2029
- })
2030
- )
2031
- } : item
2032
- );
2033
- emailStore.setState({
2034
- prependEmails: emails
2035
- });
2036
- if (responseData?.data?.hs_attachment_ids != null) {
2037
- const emailObjectId = email?.hs_object_id?.value;
2038
- const rows = state.emails?.data?.results?.rows ?? [];
2039
- const matchingRow = rows.find(
2040
- (row) => String(row.hs_object_id) === String(emailObjectId)
2041
- );
2042
- const originalPrependItem = prependEmails.find(
2043
- (item) => String(item?.hs_object_id) === String(emailObjectId)
2044
- );
2045
- const existingAttachments = matchingRow?.hs_attachment_ids ?? originalPrependItem?.hs_attachment_ids ?? [];
2046
- const newAttachments = resolveAttachmentsFromIds(
2047
- responseData.data.hs_attachment_ids,
2048
- storedAttachments
2049
- );
2050
- const mergedAttachments = [
2051
- ...existingAttachments,
2052
- ...newAttachments.filter(
2053
- (attachment) => !existingAttachments.some(
2054
- (existing) => String(existing.id) === String(attachment.id)
2055
- )
2056
- )
2057
- ];
2058
- const stateUpdates = {};
2059
- if (matchingRow && state.emails?.data?.results) {
2060
- stateUpdates.emails = {
2061
- ...state.emails,
2062
- data: {
2063
- ...state.emails.data,
2064
- results: {
2065
- ...state.emails.data.results,
2066
- rows: rows.map(
2067
- (row) => String(row.hs_object_id) === String(emailObjectId) ? { ...row, hs_attachment_ids: mergedAttachments } : row
2068
- )
2069
- }
2070
- }
2071
- };
2072
- }
2073
- if (originalPrependItem) {
2074
- stateUpdates.prependEmails = prependEmails.map(
2075
- (item) => String(item?.hs_object_id) === String(emailObjectId) ? { ...item, hs_attachment_ids: mergedAttachments } : item
2076
- );
2375
+ file: {
2376
+ list: (props = null) => {
2377
+ const { setListQueryParams } = actions6;
2378
+ setListQueryParams(props?.queryParams ?? {});
2379
+ const params = {
2380
+ // hubId: config.hubId,
2381
+ // portalId: portalId,
2382
+ objectId: props?.params?.objectId,
2383
+ id: props?.params?.id
2384
+ };
2385
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.FILES, params, queryParams: props?.queryParams });
2386
+ return HttpClient.get(apiUrl);
2387
+ },
2388
+ details: (props = null) => {
2389
+ const params = {
2390
+ // hubId: config.hubId,
2391
+ // portalId: portalId,
2392
+ objectId: props?.params?.objectId,
2393
+ id: props?.params?.id,
2394
+ rowId: props?.params?.rowId
2395
+ };
2396
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.FILE, params, queryParams: props?.queryParams });
2397
+ return HttpClient.get(apiUrl);
2398
+ },
2399
+ download: (props = null) => {
2400
+ const params = {
2401
+ objectId: props?.params?.objectId,
2402
+ id: props?.params?.id,
2403
+ rowId: props?.params?.rowId
2404
+ };
2405
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.FILE_DOWNLOAD, params, queryParams: props?.queryParams });
2406
+ return HttpClient.post(apiUrl, {});
2407
+ },
2408
+ addFolder: async (props = null) => {
2409
+ const params = { hubspotObjectTypeId: props?.hubspotObjectTypeId, ...props.params };
2410
+ const queryParams = props.queryParams;
2411
+ const payload = props.payload;
2412
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.FILES_CREATE_FOLDER, params, queryParams });
2413
+ const listQuery = fileStore.getState().queryParams ?? {};
2414
+ const response = await HttpClient.post(apiUrl, payload);
2415
+ const recordId = props?.params?.id;
2416
+ const objectTypeId = props?.params?.objectId;
2417
+ if (recordId && objectTypeId) {
2418
+ purgeEngagementCaches({
2419
+ objectTypeId,
2420
+ recordIds: [String(recordId)],
2421
+ views: ["files"],
2422
+ listQuery
2423
+ });
2077
2424
  }
2078
- if (Object.keys(stateUpdates).length > 0) {
2079
- emailStore.setState(stateUpdates);
2425
+ return response;
2426
+ },
2427
+ addFile: async (props = null) => {
2428
+ const params = { hubspotObjectTypeId: props?.hubspotObjectTypeId, ...props.params };
2429
+ const queryParams = props.queryParams;
2430
+ const payload = props.payload;
2431
+ const axiosConfig = props.config || {};
2432
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.FILES_UPLOAD, params, queryParams });
2433
+ const listQuery = fileStore.getState().queryParams ?? {};
2434
+ const response = await HttpClient.post(apiUrl, payload, {
2435
+ headers: {
2436
+ "Content-Type": "multipart/form-data"
2437
+ },
2438
+ ...axiosConfig
2439
+ });
2440
+ const recordId = props?.params?.id;
2441
+ const objectTypeId = props?.params?.objectId;
2442
+ if (recordId && objectTypeId) {
2443
+ purgeEngagementCaches({
2444
+ objectTypeId,
2445
+ recordIds: [String(recordId)],
2446
+ views: ["files"],
2447
+ listQuery
2448
+ });
2080
2449
  }
2081
- responseData.data.hs_attachment_ids = mergedAttachments;
2450
+ return response;
2082
2451
  }
2083
- return responseData;
2084
2452
  }
2085
2453
  };
2086
2454
 
@@ -2091,7 +2459,7 @@ var syncStore = createStore2({
2091
2459
  isSyncLoading: false,
2092
2460
  isSyncDisable: false
2093
2461
  });
2094
- var actions6 = {
2462
+ var actions7 = {
2095
2463
  setIsSyncLoading(status) {
2096
2464
  syncStore.setState({
2097
2465
  isSyncLoading: status,
@@ -2205,7 +2573,6 @@ function login(options) {
2205
2573
  const expiresIn = tokenData?.expiresIn;
2206
2574
  const rExpiresIn = tokenData?.refreshExpiresIn;
2207
2575
  setPortal(currentPortal);
2208
- console.log("SubscriptionType", SubscriptionType);
2209
2576
  setSubscriptionType(SubscriptionType);
2210
2577
  await setAccessToken(token, expiresIn);
2211
2578
  await setRefreshToken(refreshToken, rExpiresIn);
@@ -2476,7 +2843,7 @@ var multiObjectStore = createStore2({
2476
2843
  function getObjectKey(payload) {
2477
2844
  return String(payload?.hubspotObjectTypeId ?? "");
2478
2845
  }
2479
- var actions7 = {
2846
+ var actions8 = {
2480
2847
  setMultiObjectData(response, payload) {
2481
2848
  const key = getObjectKey(payload);
2482
2849
  const state = multiObjectStore.getState();
@@ -2583,7 +2950,7 @@ function list3(options) {
2583
2950
  };
2584
2951
  }
2585
2952
  function sideBarList(options) {
2586
- const { setMultiObjectData } = actions7;
2953
+ const { setMultiObjectData } = actions8;
2587
2954
  const { mutate, isLoading } = createMutation(
2588
2955
  async (payload) => {
2589
2956
  const response = await Client.object.sideBarList(payload);
@@ -2630,7 +2997,7 @@ function objectFormOptions(options) {
2630
2997
  }
2631
2998
  function create(options) {
2632
2999
  const { setTablePrependData } = actions2;
2633
- const { setMultiObjectPrependData } = actions7;
3000
+ const { setMultiObjectPrependData } = actions8;
2634
3001
  const { mutate, isLoading } = createMutation(
2635
3002
  async (props) => {
2636
3003
  if (props?.componentName === "sidebarTable") await setMultiObjectPrependData("loading", props);
@@ -3200,223 +3567,6 @@ function formatHubSpotActivityDateTime(timestamp, timeZone = getCurrentTimeZone(
3200
3567
  return formatHubSpotActivityDateTimeParts(timestamp, timeZone)?.formatted ?? "";
3201
3568
  }
3202
3569
 
3203
- // src/utils/cache/builders.ts
3204
- function buildCrmListPurgeTarget(objectTypeId, listQuery) {
3205
- return {
3206
- domain: "crm_object_data",
3207
- objectTypeId,
3208
- views: ["list"],
3209
- listQuery: listQuery ?? { page: 1, limit: 10, view: "LIST" }
3210
- };
3211
- }
3212
- function buildCrmSinglePurgeTarget(objectTypeId, recordIds, listQuery) {
3213
- return {
3214
- domain: "crm_object_data",
3215
- objectTypeId,
3216
- views: ["single"],
3217
- recordIds,
3218
- listQuery
3219
- };
3220
- }
3221
- function buildEngagementPurgeTarget(objectTypeId, recordIds, views, options) {
3222
- if (!recordIds.length) {
3223
- throw new Error("recordIds is required for engagement purge views");
3224
- }
3225
- return {
3226
- domain: "crm_object_data",
3227
- objectTypeId,
3228
- recordIds,
3229
- views,
3230
- fileIds: options?.fileIds,
3231
- listQuery: options?.listQuery ?? { page: 1, limit: 10 }
3232
- };
3233
- }
3234
- function buildUserSessionPurgeTarget() {
3235
- return { domain: "user_session" };
3236
- }
3237
- function buildPortalConfigPurgeTarget(objectTypeIds) {
3238
- return {
3239
- domain: "portal_object_config",
3240
- objectTypeIds
3241
- };
3242
- }
3243
- function mergePurgeTargets(...targets) {
3244
- return targets;
3245
- }
3246
- function buildCachePurgeRequest(targets, options) {
3247
- return {
3248
- mode: options?.mode ?? "soft",
3249
- warm: options?.warm ?? true,
3250
- includeContactAccess: options?.includeContactAccess ?? true,
3251
- includeShortOnHard: options?.includeShortOnHard ?? false,
3252
- confirmPortalWide: options?.confirmPortalWide ?? false,
3253
- targets
3254
- };
3255
- }
3256
-
3257
- // src/utils/cache/createCachePurgeJob.ts
3258
- function randomIdempotencyKey() {
3259
- if (typeof crypto !== "undefined" && crypto.randomUUID) {
3260
- return crypto.randomUUID();
3261
- }
3262
- return `purge-${Date.now()}-${Math.random().toString(36).slice(2)}`;
3263
- }
3264
- function mapErrorCode(status, message) {
3265
- if (status === 400 || status === 422) {
3266
- return "VALIDATION";
3267
- }
3268
- if (status === 429) {
3269
- return "RATE_LIMITED";
3270
- }
3271
- if (message?.toLowerCase().includes("disabled")) {
3272
- return "PURGE_API_DISABLED";
3273
- }
3274
- return status ? "UNKNOWN" : "NETWORK";
3275
- }
3276
- function sleep(ms) {
3277
- return new Promise((resolve) => setTimeout(resolve, ms));
3278
- }
3279
- async function createCachePurgeJob(request, options = {}) {
3280
- const idempotencyKey = options.idempotencyKey ?? randomIdempotencyKey();
3281
- try {
3282
- const headers = { "Idempotency-Key": idempotencyKey };
3283
- const response = await Client.cache.purge(
3284
- request,
3285
- headers
3286
- );
3287
- const data = response?.data;
3288
- const purgeJobId = data?.purgeJobId;
3289
- let status = data?.status;
3290
- if (options.waitForWarm && purgeJobId && request.warm !== false) {
3291
- const timeout = options.pollTimeoutMs ?? 3e4;
3292
- const interval = options.pollIntervalMs ?? 500;
3293
- const deadline = Date.now() + timeout;
3294
- while (Date.now() < deadline) {
3295
- const statusRes = await Client.cache.purgeStatus(purgeJobId);
3296
- const job = statusRes?.data;
3297
- const jobStatus = job?.status;
3298
- if (jobStatus === "completed") {
3299
- status = "completed";
3300
- break;
3301
- }
3302
- if (jobStatus === "failed") {
3303
- return {
3304
- ok: false,
3305
- purgeJobId,
3306
- status: "failed",
3307
- errorCode: "WARM_FAILED",
3308
- message: "Cache warm job failed"
3309
- };
3310
- }
3311
- await sleep(interval);
3312
- }
3313
- if (status !== "completed") {
3314
- return {
3315
- ok: false,
3316
- purgeJobId,
3317
- status: status ?? "warming",
3318
- errorCode: "WARM_FAILED",
3319
- message: "Timed out waiting for cache warm job"
3320
- };
3321
- }
3322
- }
3323
- return {
3324
- ok: true,
3325
- purgeJobId,
3326
- status,
3327
- evicted: data?.evicted,
3328
- warnings: data?.warnings
3329
- };
3330
- } catch (err) {
3331
- const axiosErr = err;
3332
- const status = axiosErr.response?.status;
3333
- const message = axiosErr.response?.data?.message ?? (err instanceof Error ? err.message : "Cache purge request failed");
3334
- return {
3335
- ok: false,
3336
- errorCode: mapErrorCode(status, message),
3337
- message
3338
- };
3339
- }
3340
- }
3341
-
3342
- // src/utils/cache/crmCacheRefresh.ts
3343
- async function purgeCrmObjectDataCache(options) {
3344
- const result = await purgeCrmListCache(options);
3345
- return result.ok;
3346
- }
3347
- async function purgeCrmListCache(options) {
3348
- const objectTypeId = options.objectTypeId?.trim();
3349
- if (!objectTypeId) {
3350
- return { ok: false, errorCode: "VALIDATION", message: "objectTypeId is required" };
3351
- }
3352
- const target = buildCrmListPurgeTarget(objectTypeId, options.listQuery);
3353
- const request = buildCachePurgeRequest([target], {
3354
- mode: options.mode,
3355
- warm: options.warm
3356
- });
3357
- return createCachePurgeJob(request, {
3358
- idempotencyKey: options.idempotencyKey,
3359
- waitForWarm: options.waitForWarm
3360
- });
3361
- }
3362
- async function purgeCrmRecordCache(options) {
3363
- const objectTypeId = options.objectTypeId?.trim();
3364
- if (!objectTypeId || !options.recordIds?.length) {
3365
- return {
3366
- ok: false,
3367
- errorCode: "VALIDATION",
3368
- message: "objectTypeId and recordIds are required"
3369
- };
3370
- }
3371
- const target = buildCrmSinglePurgeTarget(
3372
- objectTypeId,
3373
- options.recordIds,
3374
- options.listQuery
3375
- );
3376
- const request = buildCachePurgeRequest([target], {
3377
- mode: options.mode,
3378
- warm: options.warm
3379
- });
3380
- return createCachePurgeJob(request, {
3381
- idempotencyKey: options.idempotencyKey,
3382
- waitForWarm: options.waitForWarm
3383
- });
3384
- }
3385
- async function purgeEngagementCaches(options) {
3386
- const objectTypeId = options.objectTypeId?.trim();
3387
- if (!objectTypeId || !options.recordIds?.length || !options.views?.length) {
3388
- return {
3389
- ok: false,
3390
- errorCode: "VALIDATION",
3391
- message: "objectTypeId, recordIds, and views are required"
3392
- };
3393
- }
3394
- const target = buildEngagementPurgeTarget(
3395
- objectTypeId,
3396
- options.recordIds,
3397
- options.views,
3398
- { fileIds: options.fileIds, listQuery: options.listQuery }
3399
- );
3400
- const request = buildCachePurgeRequest([target], {
3401
- mode: options.mode,
3402
- warm: options.warm
3403
- });
3404
- return createCachePurgeJob(request, {
3405
- idempotencyKey: options.idempotencyKey,
3406
- waitForWarm: options.waitForWarm
3407
- });
3408
- }
3409
- async function purgeCrmCombined(options) {
3410
- const request = buildCachePurgeRequest(options.targets, {
3411
- mode: options.mode,
3412
- warm: options.warm
3413
- });
3414
- return createCachePurgeJob(request, {
3415
- idempotencyKey: options.idempotencyKey,
3416
- waitForWarm: options.waitForWarm
3417
- });
3418
- }
3419
-
3420
3570
  // src/index.ts
3421
3571
  var api = {
3422
3572
  preLogin,
@@ -3486,6 +3636,6 @@ var routeParam = {
3486
3636
  getParamDetails
3487
3637
  };
3488
3638
 
3489
- export { DEFAULT_HUBSPOT_TIMEZONE, actions2 as actions, actions3 as actions2, actions4 as actions3, actions5 as actions4, actions6 as actions5, actions7 as actions6, api, breadcrumbsDetails, buildCachePurgeRequest, buildCrmListPurgeTarget, buildCrmSinglePurgeTarget, buildEngagementPurgeTarget, buildPortalConfigPurgeTarget, buildUserSessionPurgeTarget, client_exports, createCachePurgeJob, emailStore, formatGmtOffset, formatHubSpotActivityDateTime, formatHubSpotActivityDateTimeParts, getCurrentTimeZone, getFieldErrors, getFormErrors, initializeHttpClient, mergePurgeTargets, multiObjectStore, normalizeToTimestamp, noteStore, purgeCrmCombined, purgeCrmListCache, purgeCrmObjectDataCache, purgeCrmRecordCache, purgeEngagementCaches, routeParam, store, syncStore, tableStore2 as tableStore, uploaderStore, url };
3490
- //# sourceMappingURL=chunk-HSJU2Z2S.js.map
3491
- //# sourceMappingURL=chunk-HSJU2Z2S.js.map
3639
+ export { DEFAULT_HUBSPOT_TIMEZONE, actions2 as actions, actions3 as actions2, actions4 as actions3, actions5 as actions4, actions7 as actions5, actions8 as actions6, api, breadcrumbsDetails, buildCachePurgeRequest, buildCrmListPurgeTarget, buildCrmSinglePurgeTarget, buildEngagementPurgeTarget, buildPortalConfigPurgeTarget, buildUserSessionPurgeTarget, client_exports, createCachePurgeJob, emailStore, formatGmtOffset, formatHubSpotActivityDateTime, formatHubSpotActivityDateTimeParts, getCurrentTimeZone, getFieldErrors, getFormErrors, initializeHttpClient, mergePurgeTargets, multiObjectStore, normalizeToTimestamp, noteStore, purgeCrmCombined, purgeCrmListCache, purgeCrmObjectDataCache, purgeCrmRecordCache, purgeEngagementCaches, routeParam, store, syncStore, tableStore2 as tableStore, uploaderStore, url };
3640
+ //# sourceMappingURL=chunk-P3ORKG7B.js.map
3641
+ //# sourceMappingURL=chunk-P3ORKG7B.js.map