woodsportal-client-sdk 1.1.4-dev.6 → 1.1.4-dev.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3933 @@
1
+ import { __export, ensureValidRefresh, HUBSPOT_DATA, PORTAL_ID, DEV_PORTAL_ID, HUB_ID, setRefreshCallback, getAccessToken, setRefreshToken, setAccessToken, isAuthenticateApp, isExpiresAccessToken, isCookieExpired, getRefreshToken, DEV_API_URL, getCookie, setPortal, setSubscriptionType, setLoggedInDetails, clearAccessToken, removeAllCookie } from './chunk-2SYUOWTT.js';
2
+ import axios from 'axios';
3
+ import pako from 'pako';
4
+ import { Base64 } from 'js-base64';
5
+
6
+ // src/client/index.ts
7
+ var client_exports = {};
8
+ __export(client_exports, {
9
+ Client: () => Client
10
+ });
11
+
12
+ // src/utils/localStoraget.ts
13
+ var memory = /* @__PURE__ */ new Map();
14
+ var memoryStore = {
15
+ getItem(key) {
16
+ return memory.has(key) ? memory.get(key) : null;
17
+ },
18
+ setItem(key, value) {
19
+ memory.set(key, value);
20
+ },
21
+ removeItem(key) {
22
+ memory.delete(key);
23
+ }
24
+ };
25
+ function resolveStore() {
26
+ if (typeof globalThis === "undefined") {
27
+ return memoryStore;
28
+ }
29
+ const ls = globalThis.localStorage;
30
+ if (!ls || typeof ls.getItem !== "function") {
31
+ return memoryStore;
32
+ }
33
+ try {
34
+ const probeKey = "__woodsportal_client_sdk_ls_probe__";
35
+ ls.setItem(probeKey, "1");
36
+ ls.removeItem(probeKey);
37
+ return ls;
38
+ } catch {
39
+ return memoryStore;
40
+ }
41
+ }
42
+ var storage = {
43
+ set: (key, value) => {
44
+ resolveStore().setItem(key, JSON.stringify(value));
45
+ },
46
+ get: (key) => {
47
+ const item = resolveStore().getItem(key);
48
+ return item ? JSON.parse(item) : null;
49
+ },
50
+ remove: (key) => {
51
+ resolveStore().removeItem(key);
52
+ }
53
+ };
54
+
55
+ // src/utils/config.ts
56
+ var config = {
57
+ get hubId() {
58
+ const hubSpotData = storage.get(HUBSPOT_DATA);
59
+ return hubSpotData?.[HUB_ID] || "";
60
+ },
61
+ get devPortalId() {
62
+ const hubSpotData = storage.get(HUBSPOT_DATA);
63
+ return hubSpotData?.[DEV_PORTAL_ID] || "";
64
+ },
65
+ get portalId() {
66
+ const hubSpotData = storage.get(HUBSPOT_DATA);
67
+ return hubSpotData?.[PORTAL_ID] || "";
68
+ },
69
+ get devApiUrl() {
70
+ const hubSpotData = storage.get(HUBSPOT_DATA);
71
+ return hubSpotData?.[DEV_API_URL] || "";
72
+ }
73
+ };
74
+ var setConfig = {
75
+ setDevPortalId(portalId) {
76
+ const existing = storage.get(HUBSPOT_DATA) || {};
77
+ storage.set(HUBSPOT_DATA, {
78
+ ...existing,
79
+ [PORTAL_ID]: portalId
80
+ });
81
+ }
82
+ };
83
+
84
+ // src/utils/generateApiUrl.ts
85
+ var generateApiUrl = ({
86
+ route,
87
+ params = {},
88
+ queryParams = ""
89
+ }) => {
90
+ const defaultParams = {
91
+ hubId: config.hubId,
92
+ portalId: config.portalId
93
+ };
94
+ params = { ...defaultParams, ...params };
95
+ const url2 = replaceParams(route, params);
96
+ let queryString = "";
97
+ if (queryParams && typeof queryParams === "object") {
98
+ const cleanedParams = Object.entries(queryParams).filter(([_, value]) => value !== null && value !== void 0).reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {});
99
+ queryString = new URLSearchParams(cleanedParams).toString();
100
+ }
101
+ return queryString ? `${url2}?${queryString}` : url2;
102
+ };
103
+ function replaceParams(template, values) {
104
+ return template.replace(
105
+ /\$\{(\w+)\}/g,
106
+ (_, key) => key in values ? String(values[key]) : `\${${key}}`
107
+ );
108
+ }
109
+
110
+ // src/client/api-endpoints.ts
111
+ var API_ENDPOINTS = {
112
+ // Auth
113
+ PRE_LOGIN: "/api/auth/pre-login",
114
+ LOGIN: "/api/auth/login",
115
+ AUTH_REFRESH: "/api/auth/refresh",
116
+ FORGET_PASSWORD: "/api/auth/forget-password",
117
+ RESET_PASSWORD_VERIFY_TOKEN: "/api/auth/token/validate",
118
+ RESET_PASSWORD: "/api/auth/reset-password",
119
+ VERIFY_EMAIL: "/api/auth/verify-email",
120
+ REGISTER_EXISTING_USER: "/api/auth/existing-user-register",
121
+ RESEND_EMAIL: "/api/auth/resend-email",
122
+ VERIFY_EMAIL_RESEND: "/api/auth/verify-email/resend",
123
+ LOGOUT: "/api/auth/logout",
124
+ // SSO
125
+ SSO_DETAILS: "/api/auth/sso/active",
126
+ SSO_URL: "/api/auth/sso/authorize",
127
+ SSO_CALLBACK: "/api/auth/sso/callback",
128
+ // User
129
+ ME: "/api/auth/me",
130
+ PROFILE: "/api/${hubId}/${portalId}/profiles",
131
+ CHANGE_PASSWORD: "/api/auth/change-password",
132
+ // Pipeline
133
+ PIPELINES: "/api/${hubId}/${portalId}/hubspot-object-pipelines/${hubspotObjectTypeId}",
134
+ // Stage
135
+ STAGES: "/api/${hubId}/${portalId}/hubspot-object-pipelines/${objectTypeId}/${pipelineId}/stages",
136
+ // Cache purge (replaces cache=false refresh; requires features.cache-purge-api-enabled on API)
137
+ CACHE_PURGE: "/api/${hubId}/${portalId}/cache-purge-jobs",
138
+ CACHE_PURGE_STATUS: "/api/${hubId}/${portalId}/cache-purge-jobs/${purgeJobId}",
139
+ /** @deprecated Use CACHE_PURGE */
140
+ CACHE_PURGE_LEGACY: "/api/${hubId}/${portalId}/cache/purge",
141
+ /** @deprecated Use CACHE_PURGE_STATUS */
142
+ CACHE_PURGE_STATUS_LEGACY: "/api/${hubId}/${portalId}/cache/purge/${purgeJobId}",
143
+ // Object (read on hubspot-object-data; form layout on hubspot-object-forms)
144
+ OBJECTS: "/api/${hubId}/${portalId}/hubspot-object-data/${hubspotObjectTypeId}/records",
145
+ OBJECTS_FORM: "/api/${hubId}/${portalId}/hubspot-object-forms/${hubspotObjectTypeId}/fields",
146
+ OBJECTS_FORM_OPTIONS: "/api/${hubId}/${portalId}/hubspot-object-forms/${formId}/${objectTypeId}",
147
+ RECORDS_CREATE: "/api/${hubId}/${portalId}/hubspot-object-data/${hubspotObjectTypeId}/records",
148
+ RECORDS_UPDATE: "/api/${hubId}/${portalId}/hubspot-object-data/${objectId}/records/${id}",
149
+ RECORDS_ASSOCIATE: "/api/${hubId}/${portalId}/hubspot-object-data/${fromObjectTypeId}/records/${fromRecordId}/associations/${toObjectTypeId}",
150
+ RECORDS_DISASSOCIATE: "/api/${hubId}/${portalId}/hubspot-object-data/${fromObjectTypeId}/records/${fromRecordId}/associations/${toObjectTypeId}",
151
+ /** @deprecated Use RECORDS_CREATE */
152
+ OBJECTS_CREATE: "/api/${hubId}/${portalId}/hubspot-object-forms/${hubspotObjectTypeId}/fields",
153
+ /** @deprecated Use RECORDS_ASSOCIATE */
154
+ OBJECTS_CREATE_EXISTING: "/api/${hubId}/${portalId}/hubspot-object-forms/:fromObjectTypeId/:fromRecordId/associations/:toObjectTypeId",
155
+ OBJECTS_DETAILS: "/api/${hubId}/${portalId}/hubspot-object-data/${objectId}/records/${id}",
156
+ /** @deprecated Use RECORDS_UPDATE */
157
+ OBJECTS_DETAILS_UPDATE: "/api/${hubId}/${portalId}/hubspot-object-forms/${objectId}/records/${id}",
158
+ OBJECTS_DETAILS_UPDATE_LEGACY: "/api/${hubId}/${portalId}/hubspot-object-forms/${objectId}/properties/${id}",
159
+ // Notes (nested under CRM record)
160
+ NOTES: "/api/${hubId}/${portalId}/hubspot-object-data/${objectId}/records/${id}/notes",
161
+ NOTES_CREATE: "/api/${hubId}/${portalId}/hubspot-object-data/${objectId}/records/${id}/notes",
162
+ NOTES_DETAILS_UPDATE: "/api/${hubId}/${portalId}/hubspot-object-data/${objectId}/records/${id}/notes/${note_id}",
163
+ NOTES_IMAGE_UPLOAD: "/api/${hubId}/${portalId}/hubspot-object-data/${objectId}/records/${id}/notes/images",
164
+ NOTES_ATTACHMENT_UPLOAD: "/api/${hubId}/${portalId}/hubspot-object-data/${objectId}/records/${id}/notes/attachments",
165
+ NOTES_ATTACHMENT_UPDATE: "/api/${hubId}/${portalId}/hubspot-object-data/${objectId}/records/${id}/notes/attachments/${note_id}",
166
+ // Email (nested under CRM record)
167
+ EMAILS: "/api/${hubId}/${portalId}/hubspot-object-data/${objectId}/records/${id}/emails",
168
+ EMAILS_CREATE: "/api/${hubId}/${portalId}/hubspot-object-data/${objectId}/records/${id}/emails",
169
+ EMAILS_DETAILS_UPDATE: "/api/${hubId}/${portalId}/hubspot-object-data/${objectId}/records/${id}/emails/${email_id}",
170
+ EMAILS_IMAGE_UPLOAD: "/api/${hubId}/${portalId}/hubspot-object-data/${objectId}/records/${id}/emails/images",
171
+ EMAILS_ATTACHMENT_UPLOAD: "/api/${hubId}/${portalId}/hubspot-object-data/${objectId}/records/${id}/emails/attachments",
172
+ EMAILS_ATTACHMENT_UPDATE: "/api/${hubId}/${portalId}/hubspot-object-data/${objectId}/records/${id}/emails/attachments/${email_id}",
173
+ // File manager (nested under CRM record)
174
+ FILES: "/api/${hubId}/${portalId}/hubspot-object-data/${objectId}/records/${id}/files",
175
+ FILE: "/api/${hubId}/${portalId}/hubspot-object-data/${objectId}/records/${id}/files/${rowId}",
176
+ FILE_DOWNLOAD: "/api/${hubId}/${portalId}/hubspot-object-data/${objectId}/records/${id}/files/${rowId}/download",
177
+ FILES_CREATE_FOLDER: "/api/${hubId}/${portalId}/hubspot-object-data/${objectId}/records/${id}/folders",
178
+ FILES_UPLOAD: "/api/${hubId}/${portalId}/hubspot-object-data/${objectId}/records/${id}/files"
179
+ };
180
+
181
+ // src/client/config.ts
182
+ var config2 = {
183
+ baseURL: ""
184
+ };
185
+
186
+ // src/client/http-clint.ts
187
+ var axiosInstance = null;
188
+ var config3 = {};
189
+ function initializeHttpClient(clientConfig) {
190
+ config3 = clientConfig;
191
+ const baseURL = config?.devApiUrl || config3.baseURL;
192
+ if (!baseURL) {
193
+ throw new Error(
194
+ "WoodsPortal SDK HTTP client is not configured. Call initializeHttpClient({ baseURL }) at app startup."
195
+ );
196
+ }
197
+ const timeout = config3.timeout ?? 5e4;
198
+ axiosInstance = axios.create({
199
+ baseURL,
200
+ timeout,
201
+ headers: {
202
+ "Content-Type": "application/json",
203
+ ...config3.headers
204
+ }
205
+ });
206
+ setRefreshCallback(getAuthRefreshToken);
207
+ axiosInstance.interceptors.request.use((config4) => {
208
+ const token = getAccessToken();
209
+ if (token) {
210
+ config4.headers.set("Authorization", `Bearer ${token}`);
211
+ }
212
+ return config4;
213
+ });
214
+ axiosInstance.interceptors.response.use(
215
+ (response) => response,
216
+ (error) => {
217
+ if (error.response && error.response.status === 401) {
218
+ config3.skipCurrentPublicPath?.() ?? false;
219
+ }
220
+ return Promise.reject(error);
221
+ }
222
+ );
223
+ }
224
+ function getAxiosInstance() {
225
+ if (!axiosInstance) {
226
+ initializeHttpClient({
227
+ baseURL: config2.baseURL,
228
+ timeout: 5e4
229
+ });
230
+ }
231
+ return axiosInstance;
232
+ }
233
+ function formatBooleanSearchParam(key, value) {
234
+ return value ? `${key}:1` : `${key}:`;
235
+ }
236
+ var HttpClient = class {
237
+ static async get(url2, params) {
238
+ await ensureValidRefresh();
239
+ const response = await getAxiosInstance().get(url2, { params });
240
+ return response.data;
241
+ }
242
+ static async post(url2, data, options) {
243
+ await ensureValidRefresh();
244
+ const response = await getAxiosInstance().post(url2, data, options);
245
+ return response.data;
246
+ }
247
+ static async put(url2, data) {
248
+ await ensureValidRefresh();
249
+ const response = await getAxiosInstance().put(url2, data);
250
+ return response.data;
251
+ }
252
+ static async delete(url2, config4) {
253
+ await ensureValidRefresh();
254
+ const response = await getAxiosInstance().delete(url2, config4);
255
+ return response.data;
256
+ }
257
+ static formatSearchParams(params) {
258
+ return Object.entries(params).filter(([, value]) => Boolean(value)).map(
259
+ ([k, v]) => [
260
+ "type",
261
+ "categories",
262
+ "tags",
263
+ "author",
264
+ "manufacturer",
265
+ "shops",
266
+ "refund_reason"
267
+ ].includes(k) ? `${k}.slug:${v}` : ["is_approved"].includes(k) ? formatBooleanSearchParam(k, v) : `${k}:${v}`
268
+ ).join(";");
269
+ }
270
+ };
271
+ var AuthHttpClient = class {
272
+ static async get(url2, params) {
273
+ const response = await getAxiosInstance().get(url2, { params });
274
+ return response.data;
275
+ }
276
+ static async post(url2, data, options) {
277
+ const response = await getAxiosInstance().post(url2, data, options);
278
+ return response.data;
279
+ }
280
+ static async put(url2, data, options) {
281
+ const response = await getAxiosInstance().put(url2, data, options);
282
+ return response.data;
283
+ }
284
+ };
285
+ function getFormErrors(error) {
286
+ if (axios.isAxiosError(error)) {
287
+ return error.response?.data?.message ?? null;
288
+ }
289
+ return null;
290
+ }
291
+ function getFieldErrors(error) {
292
+ if (axios.isAxiosError(error)) {
293
+ return error.response?.data?.errors ?? null;
294
+ }
295
+ return null;
296
+ }
297
+ async function getAuthRefreshToken(refreshToken) {
298
+ if (refreshToken == null || refreshToken.trim() === "") {
299
+ return { token: null, success: false };
300
+ }
301
+ try {
302
+ const headers = {};
303
+ if (config.devPortalId) {
304
+ headers["X-Dev-Portal-Id"] = config.devPortalId;
305
+ }
306
+ const api_url = generateApiUrl({ route: API_ENDPOINTS.AUTH_REFRESH, queryParams: { hubId: config.hubId } });
307
+ const response = await getAxiosInstance().post(
308
+ api_url,
309
+ { refreshToken },
310
+ { headers }
311
+ );
312
+ const maybeData = response?.data?.data || response?.data;
313
+ const tokenData = maybeData?.tokenData || maybeData || {};
314
+ const newRefreshToken = tokenData?.refreshToken;
315
+ const token = tokenData?.token;
316
+ const expiresIn = tokenData?.expiresIn;
317
+ const rExpiresIn = tokenData?.refreshExpiresIn;
318
+ const rExpiresAt = tokenData?.refreshExpiresAt;
319
+ if (typeof newRefreshToken === "string") {
320
+ let rExpires = 0;
321
+ if (typeof rExpiresIn === "number") {
322
+ rExpires = Date.now() + rExpiresIn * 1e3;
323
+ } else if (typeof rExpiresAt === "number") {
324
+ rExpires = rExpiresAt * 1e3;
325
+ }
326
+ setRefreshToken(newRefreshToken, rExpires);
327
+ }
328
+ if (typeof token === "string") {
329
+ setAccessToken(token, typeof expiresIn === "number" ? expiresIn : void 0);
330
+ return { token, success: true };
331
+ }
332
+ return { token: null, success: false };
333
+ } catch {
334
+ return { token: null, success: false };
335
+ }
336
+ }
337
+
338
+ // src/data/user.ts
339
+ var PROFILE = null;
340
+ var setProfileData = (data) => {
341
+ PROFILE = data;
342
+ };
343
+ var getProfileData = () => {
344
+ return PROFILE;
345
+ };
346
+ function convertToBase64(obj) {
347
+ try {
348
+ if (!obj) return "";
349
+ const json = JSON.stringify(obj);
350
+ const compressed = pako.deflate(json);
351
+ const base64 = Base64.fromUint8Array(compressed, true);
352
+ return base64;
353
+ } catch (error) {
354
+ console.error("Failed to encode object:", error);
355
+ return "";
356
+ }
357
+ }
358
+ function decodeToBase64(encoded) {
359
+ try {
360
+ if (!encoded) return null;
361
+ const uint8Array = Base64.toUint8Array(encoded);
362
+ const decompressed = pako.inflate(uint8Array, { to: "string" });
363
+ return JSON.parse(decompressed);
364
+ } catch (error) {
365
+ console.error("Failed to decode object:", error);
366
+ return null;
367
+ }
368
+ }
369
+
370
+ // src/breadcrumb/url-utils.ts
371
+ function mapKeysDeep(obj, keyMap2) {
372
+ if (Array.isArray(obj)) {
373
+ return obj.map((item) => mapKeysDeep(item, keyMap2));
374
+ } else if (obj !== null && typeof obj === "object") {
375
+ return Object.entries(obj).reduce((acc, [key, value]) => {
376
+ const mappedKey = keyMap2[key] || key;
377
+ acc[mappedKey] = mapKeysDeep(value, keyMap2);
378
+ return acc;
379
+ }, {});
380
+ }
381
+ return obj;
382
+ }
383
+ function isMessingParent(breadcrumbs) {
384
+ let lastItem = breadcrumbs[breadcrumbs.length - 1];
385
+ let lastItem2 = breadcrumbs[breadcrumbs.length - 2];
386
+ let lastItem3 = breadcrumbs[breadcrumbs.length - 3];
387
+ return lastItem?.o_r_id && (!lastItem2?.o_r_id && lastItem2?.o_t_id) && lastItem3?.o_r_id ? true : false;
388
+ }
389
+ function isMessingParentLastItem(breadcrumbs) {
390
+ let lastItem = breadcrumbs[breadcrumbs.length - 1];
391
+ let lastItem2 = breadcrumbs[breadcrumbs.length - 2];
392
+ return !lastItem?.o_t_id && (lastItem2?.o_r_id && lastItem2?.o_t_id) ? false : true;
393
+ }
394
+ function breadcrumbStage(breadcrumbItems) {
395
+ let breadcrumbType = "child";
396
+ if (breadcrumbItems.length === 1) {
397
+ breadcrumbType = "root";
398
+ } else if (breadcrumbItems.length === 2) {
399
+ breadcrumbType = "root_details";
400
+ }
401
+ return breadcrumbType;
402
+ }
403
+ var generateUrl = (props, breadcrumbs) => {
404
+ const newBase64 = convertToBase64(breadcrumbs);
405
+ let url2 = "";
406
+ if (props?.objectTypeId && props?.recordId) {
407
+ url2 = `/${props?.recordId}/${props?.objectTypeId}/${props?.recordId}?b=${newBase64}`;
408
+ } else {
409
+ url2 = `/association/${props?.objectTypeId}?b=${newBase64}`;
410
+ }
411
+ return url2;
412
+ };
413
+ function getTotalParentLength(data) {
414
+ return data.filter(
415
+ (item) => (item.pt || item.o_t_id) && !item.o_r_id
416
+ ).length;
417
+ }
418
+ var generatePath = (breadcrumbs, breadcrumb, index) => {
419
+ const bc = convertToBase64(breadcrumbs.slice(0, index + 1));
420
+ if (index === 0) {
421
+ const pathBase = breadcrumb?.pt || `/${breadcrumb?.o_t_id}`;
422
+ const normalizedPath = pathBase.startsWith("/") ? pathBase : `/${pathBase}`;
423
+ return {
424
+ name: breadcrumb?.n,
425
+ path: `${normalizedPath}?b=${bc}`
426
+ };
427
+ } else if (index === 1) {
428
+ if (breadcrumb?.isHome) {
429
+ return {
430
+ name: breadcrumb?.n,
431
+ path: `/association/${breadcrumb?.o_t_id}?b=${bc}`
432
+ };
433
+ }
434
+ return {
435
+ name: breadcrumb?.n,
436
+ path: `/${breadcrumb?.o_r_id}/${breadcrumb?.o_t_id}/${breadcrumb?.o_r_id}?b=${bc}`
437
+ };
438
+ } else {
439
+ if (breadcrumb?.o_t_id && breadcrumb?.o_r_id && !breadcrumb?.isHome) {
440
+ return {
441
+ name: breadcrumb?.n,
442
+ path: `/${breadcrumb?.o_r_id}/${breadcrumb?.o_t_id}/${breadcrumb?.o_r_id}?b=${bc}`
443
+ };
444
+ } else {
445
+ return {
446
+ name: breadcrumb?.n,
447
+ path: `/association/${breadcrumb?.o_t_id}?b=${bc}`
448
+ };
449
+ }
450
+ }
451
+ };
452
+
453
+ // src/breadcrumb/key-map.ts
454
+ var keyMap = {
455
+ dp: "defPermissions",
456
+ n: "name",
457
+ sort: "sort",
458
+ o_t_id: "objectTypeId",
459
+ s: "search",
460
+ fPn: "filterPropertyName",
461
+ fO: "filterOperator",
462
+ fV: "filterValue",
463
+ c: "cache",
464
+ isPC: "isPrimaryCompany",
465
+ v: "view",
466
+ l: "limit",
467
+ pt: "path",
468
+ p: "page",
469
+ a: "after",
470
+ aPip: "activePipeline",
471
+ aT: "activeTab",
472
+ cT: "create",
473
+ dP: "display",
474
+ dL: "display_label",
475
+ pId: "pipeline_id"
476
+ };
477
+
478
+ // src/utils/url.ts
479
+ var ticketHubspotObjectTypeId = () => {
480
+ const { getParamDetails: getParamDetails2 } = routeParam;
481
+ const paramDetails = getParamDetails2();
482
+ if (
483
+ // this hubspotObjectTypeId only for main contact ticket object type
484
+ paramDetails?.breadcrumbs?.length === 2 && paramDetails?.breadcrumbs[0]?.pt === "/0-5"
485
+ ) {
486
+ return "0-1";
487
+ }
488
+ if (
489
+ // this hubspotObjectTypeId only for main company ticket object type
490
+ paramDetails?.breadcrumbs?.length === 2 && paramDetails?.breadcrumbs[0]?.pt === "/0-5-c"
491
+ ) {
492
+ return "0-2";
493
+ }
494
+ return "";
495
+ };
496
+
497
+ // src/utils/param.ts
498
+ function getParam(paramName) {
499
+ if (typeof globalThis === "undefined" || !globalThis.location) return null;
500
+ const hash = globalThis.location.hash || "";
501
+ if (!hash.startsWith("#/")) return null;
502
+ const hashWithoutHash = hash.startsWith("#") ? hash.substring(1) : hash;
503
+ const queryString = hashWithoutHash.split("?")[1];
504
+ if (!queryString) return null;
505
+ const params = new URLSearchParams(queryString);
506
+ return params.get(paramName);
507
+ }
508
+ function getPath() {
509
+ if (typeof globalThis === "undefined" || !globalThis.location) return null;
510
+ const hash = globalThis.location.hash || "";
511
+ if (!hash.startsWith("#/")) return null;
512
+ return hash.slice(1).split("?")[0];
513
+ }
514
+
515
+ // src/breadcrumb/param.ts
516
+ var getRouteMenu = (path) => {
517
+ const apiRoutes = globalThis?.apiRoutes || [];
518
+ return apiRoutes.find((menu) => menu?.path === path);
519
+ };
520
+ var getRouteDetails = () => {
521
+ const search = getParam("b");
522
+ const breadcrumbs = decodeToBase64(search) || [];
523
+ const lastItem = breadcrumbs[breadcrumbs.length - 1];
524
+ const mapped = lastItem ? mapKeysDeep(lastItem, keyMap) : null;
525
+ return { routeDetails: mapped };
526
+ };
527
+ var getParamDetails = (props, isDetailsPage = false) => {
528
+ const search = getParam("b");
529
+ let breadcrumbs = decodeToBase64(search) || [];
530
+ if (breadcrumbs.length > 0 && breadcrumbs?.[0]?.isHome) {
531
+ breadcrumbs = breadcrumbs.slice(1);
532
+ }
533
+ let mediatorObjectTypeId = "";
534
+ let mediatorObjectRecordId = "";
535
+ let parentObjectTypeId = "";
536
+ let parentObjectRecordId = "";
537
+ let lastItem = breadcrumbs[breadcrumbs.length - 1];
538
+ const lastItem2 = breadcrumbs[breadcrumbs.length - 2];
539
+ const lastItem3 = breadcrumbs[breadcrumbs.length - 3];
540
+ if (isDetailsPage === true && lastItem && "prm" in lastItem) {
541
+ delete lastItem.prm;
542
+ }
543
+ if (breadcrumbs.length > 1) {
544
+ if (props?.type === "ticket" || props?.type === "association") {
545
+ mediatorObjectTypeId = breadcrumbs[1]?.o_t_id || "";
546
+ mediatorObjectRecordId = breadcrumbs[1]?.o_r_id || "";
547
+ parentObjectTypeId = lastItem?.o_t_id || "";
548
+ parentObjectRecordId = lastItem?.o_r_id || "";
549
+ } else {
550
+ if (breadcrumbs.length > 2) {
551
+ mediatorObjectTypeId = breadcrumbs[1]?.o_t_id || "";
552
+ mediatorObjectRecordId = breadcrumbs[1]?.o_r_id || "";
553
+ }
554
+ if (!lastItem?.o_r_id && breadcrumbs.length > 2) {
555
+ parentObjectTypeId = lastItem2?.o_t_id || "";
556
+ parentObjectRecordId = lastItem2?.o_r_id || "";
557
+ }
558
+ if (lastItem?.o_r_id && breadcrumbs.length > 2) {
559
+ parentObjectTypeId = lastItem3?.o_t_id || "";
560
+ parentObjectRecordId = lastItem3?.o_r_id || "";
561
+ }
562
+ if (lastItem2?.o_t_id === "0-5" && !parentObjectTypeId && !parentObjectRecordId) {
563
+ parentObjectTypeId = lastItem2?.o_t_id || "";
564
+ parentObjectRecordId = lastItem2?.o_r_id || "";
565
+ }
566
+ }
567
+ }
568
+ let paramsObject = {};
569
+ if (breadcrumbs[0]?.prm?.isPC || breadcrumbs[1]?.prm?.isPC || lastItem?.prm?.isPC) {
570
+ paramsObject["isPrimaryCompany"] = true;
571
+ }
572
+ if (parentObjectTypeId && parentObjectRecordId) {
573
+ paramsObject["parentObjectTypeId"] = parentObjectTypeId;
574
+ paramsObject["parentObjectRecordId"] = parentObjectRecordId;
575
+ }
576
+ if (mediatorObjectTypeId && mediatorObjectRecordId) {
577
+ paramsObject["mediatorObjectTypeId"] = mediatorObjectTypeId;
578
+ paramsObject["mediatorObjectRecordId"] = mediatorObjectRecordId;
579
+ }
580
+ const mappedLastItemParam = Object.fromEntries(
581
+ Object.entries(lastItem?.prm || {}).map(([key, value]) => [
582
+ keyMap[key] || key,
583
+ // use mapped name if exists, else keep original
584
+ value
585
+ ])
586
+ );
587
+ let queryString = null;
588
+ if (props?.type === "association") {
589
+ queryString = new URLSearchParams({ ...paramsObject, ...{ cache: false } }).toString();
590
+ } else {
591
+ queryString = new URLSearchParams({ ...paramsObject, ...mappedLastItemParam }).toString();
592
+ }
593
+ let params = queryString ? `?${queryString}` : "";
594
+ const totalParentLength = getTotalParentLength(breadcrumbs);
595
+ let parentAccessLabel = false;
596
+ if (breadcrumbs[0]?.prm?.isPC && totalParentLength > 2 || // company object
597
+ !breadcrumbs[0]?.prm?.isPC && totalParentLength > 3 || // normal object
598
+ breadcrumbs[0]?.prm?.isPC && totalParentLength > 1 && props?.type === "ticket" || // company ticket
599
+ !breadcrumbs[0]?.prm?.isPC && totalParentLength > 2 && props?.type === "ticket") {
600
+ parentAccessLabel = true;
601
+ }
602
+ return {
603
+ breadcrumbs,
604
+ // paramsObject: Object.keys(mParamsObject).length === 0 ? null : mParamsObject,
605
+ paramsObject,
606
+ params,
607
+ parentAccessLabel
608
+ };
609
+ };
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
+
644
+ // src/breadcrumb/url.ts
645
+ var useUpdateLink = () => {
646
+ const updateLink = async (props, displayName = "prm") => {
647
+ const search = getParam("b");
648
+ const pathname = getPath();
649
+ let breadcrumbs = decodeToBase64(search) || [];
650
+ if (breadcrumbs.length < 1) {
651
+ const routeMenu = getRouteMenu(pathname);
652
+ breadcrumbs = [
653
+ {
654
+ n: routeMenu?.title,
655
+ pt: routeMenu?.path
656
+ }
657
+ ];
658
+ }
659
+ const lastBreadcrumb = breadcrumbs[breadcrumbs.length - 1];
660
+ if (displayName) {
661
+ const ex = await getDeep(lastBreadcrumb, displayName) || {};
662
+ await setDeep(lastBreadcrumb, displayName, {
663
+ ...ex,
664
+ ...props
665
+ });
666
+ } else {
667
+ await Object.assign(lastBreadcrumb, props);
668
+ }
669
+ const newBase64 = convertToBase64(breadcrumbs);
670
+ updateBParam(newBase64);
671
+ };
672
+ function setDeep(obj, path, value) {
673
+ const keys = path.split(".");
674
+ let curr = obj;
675
+ for (let i = 0; i < keys.length - 1; i++) {
676
+ if (!curr[keys[i]] || typeof curr[keys[i]] !== "object") {
677
+ curr[keys[i]] = {};
678
+ }
679
+ curr = curr[keys[i]];
680
+ }
681
+ curr[keys[keys.length - 1]] = value;
682
+ return curr;
683
+ }
684
+ function getDeep(obj, path) {
685
+ return path.split(".").reduce((acc, key) => acc?.[key], obj);
686
+ }
687
+ const getLinkParams = (displayName = "prm") => {
688
+ const search = getParam("b");
689
+ let breadcrumbs = decodeToBase64(search) || [];
690
+ if (breadcrumbs.length < 1) return null;
691
+ const lastItem = breadcrumbs[breadcrumbs.length - 1];
692
+ const getDeep2 = (obj, path) => {
693
+ return path.split(".").reduce((acc, key) => acc?.[key], obj);
694
+ };
695
+ const expandKeys = (obj) => {
696
+ return Object.fromEntries(
697
+ Object.entries(obj).map(([key, value]) => [
698
+ keyMap[key] || key,
699
+ // map if exists, else keep original
700
+ value
701
+ ])
702
+ );
703
+ };
704
+ const nestedValue = displayName ? getDeep2(lastItem, displayName) : null;
705
+ const output = nestedValue ? expandKeys(nestedValue) : null;
706
+ return output;
707
+ };
708
+ const filterParams = (displayName = "prm") => {
709
+ const search = getParam("b");
710
+ let breadcrumbs = decodeToBase64(search) || [];
711
+ if (breadcrumbs.length < 1) return null;
712
+ const lastItem = breadcrumbs[breadcrumbs.length - 1];
713
+ const getDeep2 = (obj, path) => {
714
+ return path.split(".").reduce((acc, key) => acc?.[key], obj);
715
+ };
716
+ const expandKeys = (obj) => {
717
+ return Object.fromEntries(
718
+ Object.entries(obj).map(([key, value]) => [
719
+ keyMap[key] || key,
720
+ // map if exists, else keep original
721
+ value
722
+ ])
723
+ );
724
+ };
725
+ const nestedValue = displayName ? getDeep2(lastItem, displayName) : null;
726
+ const output = nestedValue ? expandKeys(nestedValue) : expandKeys(lastItem);
727
+ return output;
728
+ };
729
+ return { updateLink, getLinkParams, filterParams };
730
+ };
731
+ var updateBParam = (newValue) => {
732
+ if (typeof globalThis === "undefined" || !globalThis.location) return;
733
+ const hash = globalThis.location.hash || "";
734
+ if (!hash.startsWith("#/")) return;
735
+ const withoutHash = hash.slice(2);
736
+ const [path, queryString] = withoutHash.split("?");
737
+ const params = new URLSearchParams(queryString || "");
738
+ params.set("b", newValue);
739
+ const newHash = `#/${path}?${params.toString()}`;
740
+ if (typeof globalThis !== "undefined" && globalThis.history && globalThis.history.replaceState) {
741
+ globalThis.history.replaceState(null, "", newHash);
742
+ }
743
+ };
744
+
745
+ // src/store/use-table.ts
746
+ var pageLimit = 10;
747
+ var tableStore = createStore((set, get) => ({
748
+ // ==============================
749
+ // STATE
750
+ // ==============================
751
+ tableUniqueId: null,
752
+ gridData: [],
753
+ sort: "-hs_createdate",
754
+ limit: 10,
755
+ after: "",
756
+ page: 1,
757
+ nextPage: 1,
758
+ stageId: "",
759
+ totalItems: 1,
760
+ numOfPages: 1,
761
+ currentPage: 1,
762
+ search: "",
763
+ filterPropertyName: "hs_pipeline",
764
+ filterOperator: "eq",
765
+ filterValue: "",
766
+ isPrimaryCompany: null,
767
+ view: null,
768
+ selectedPipeline: "",
769
+ tableParam: {},
770
+ tableDefPermissions: {},
771
+ tableData: [],
772
+ tablePrependData: [],
773
+ // ==============================
774
+ // BASIC SETTERS
775
+ // ==============================
776
+ setTableUniqueId: (v) => set({ tableUniqueId: v }),
777
+ setSort: (v) => set({ sort: v }),
778
+ setLimit: (v) => set({ limit: v }),
779
+ setAfter: (v) => set({ after: v }),
780
+ setPage: (v) => set({ page: v }),
781
+ setNextPage: (v) => set({ nextPage: v }),
782
+ setStageId: (v) => set({ stageId: v }),
783
+ setTotalItems: (v) => set({ totalItems: v }),
784
+ setNumOfPages: (v) => set({ numOfPages: v }),
785
+ setCurrentPage: (v) => set({ currentPage: v }),
786
+ setSearch: (v) => set({ search: v }),
787
+ setFilterPropertyName: (v) => set({ filterPropertyName: v }),
788
+ setFilterOperator: (v) => set({ filterOperator: v }),
789
+ setFilterValue: (v) => set({ filterValue: v }),
790
+ setIsPrimaryCompany: (v) => set({ isPrimaryCompany: v }),
791
+ // ==============================
792
+ // VIEW
793
+ // ==============================
794
+ setView: (mView) => {
795
+ set({
796
+ page: getAuthSubscriptionType() === "FREE" ? "" : 1,
797
+ view: mView
798
+ });
799
+ },
800
+ // ==============================
801
+ // PIPELINE
802
+ // ==============================
803
+ changePipeline: (mView) => {
804
+ set({
805
+ page: getAuthSubscriptionType() === "FREE" ? "" : 1,
806
+ selectedPipeline: mView || ""
807
+ });
808
+ },
809
+ setSelectedPipeline: (pipelines, pipeLineId) => {
810
+ let filterValue = "";
811
+ if (pipeLineId) {
812
+ const pipelineSingle = pipelines.find(
813
+ (pipeline) => pipeline.pipelineId === pipeLineId
814
+ );
815
+ filterValue = pipelineSingle?.pipelineId || "";
816
+ }
817
+ set({
818
+ filterPropertyName: "hs_pipeline",
819
+ filterOperator: "eq",
820
+ filterValue,
821
+ selectedPipeline: filterValue
822
+ });
823
+ },
824
+ // ==============================
825
+ // RESET
826
+ // ==============================
827
+ resetTableParam: () => {
828
+ set({
829
+ sort: "-hs_createdate",
830
+ limit: pageLimit,
831
+ after: "",
832
+ page: getAuthSubscriptionType() === "FREE" ? "" : 1,
833
+ totalItems: 1,
834
+ numOfPages: 1,
835
+ currentPage: 1,
836
+ search: "",
837
+ filterPropertyName: "hs_pipeline",
838
+ filterOperator: "eq",
839
+ filterValue: "",
840
+ isPrimaryCompany: null,
841
+ selectedPipeline: ""
842
+ });
843
+ },
844
+ // ==============================
845
+ // PARAM BUILDER
846
+ // ==============================
847
+ getTableParam: (companyAsMediator, currentPageOverride) => {
848
+ const state = get();
849
+ const baseParams = {
850
+ sort: state.sort,
851
+ search: state.search,
852
+ filterPropertyName: state.filterPropertyName,
853
+ filterOperator: state.filterOperator,
854
+ filterValue: state.selectedPipeline,
855
+ cache: true,
856
+ isPrimaryCompany: companyAsMediator || false,
857
+ view: state.view
858
+ };
859
+ if (getAuthSubscriptionType() === "FREE") {
860
+ return {
861
+ ...baseParams,
862
+ after: state.page
863
+ };
864
+ }
865
+ return {
866
+ ...baseParams,
867
+ limit: state.limit,
868
+ page: currentPageOverride || state.page,
869
+ ...state.after && {
870
+ after: state.after
871
+ }
872
+ };
873
+ },
874
+ // ==============================
875
+ // GRID DATA
876
+ // ==============================
877
+ setGridData: async (type, deals) => {
878
+ if (type === "reset") {
879
+ await set({ gridData: [] });
880
+ return [];
881
+ }
882
+ if (type === "directly") {
883
+ await set({ gridData: deals });
884
+ return deals;
885
+ }
886
+ const finalData = await deals.map(
887
+ (deal) => {
888
+ const cards = deal?.data?.results?.rows?.map(
889
+ (row) => ({
890
+ id: row?.hs_object_id,
891
+ ...row,
892
+ hubspotObjectTypeId: type === "deals" ? "0-3" : "0-5"
893
+ })
894
+ ) || [];
895
+ return {
896
+ id: deal.id,
897
+ name: deal.label,
898
+ count: deal?.data?.total,
899
+ ...deal,
900
+ cards
901
+ };
902
+ }
903
+ );
904
+ await set({ gridData: finalData });
905
+ return finalData;
906
+ },
907
+ // ==============================
908
+ // DEFAULT PIPELINE
909
+ // ==============================
910
+ setDefaultPipeline(data, hubspotObjectTypeId) {
911
+ if (!data) {
912
+ set({ selectedPipeline: "" });
913
+ return "";
914
+ }
915
+ const { updateLink, filterParams } = useUpdateLink();
916
+ const params = filterParams();
917
+ const excludedIds = ["0-1", "0-2", "0-3", "0-4", "0-5", "home"];
918
+ const state = get();
919
+ const view = state.view;
920
+ const selectedPipeline = state.selectedPipeline;
921
+ let defaultPipelineId = "";
922
+ let mFilterValue = "";
923
+ const defaultPipeline = data?.data?.[0];
924
+ if (excludedIds.includes(hubspotObjectTypeId)) {
925
+ defaultPipelineId = defaultPipeline?.pipelineId || "";
926
+ }
927
+ if (params && params?.filterPropertyName === "hs_pipeline" && params?.filterValue) {
928
+ mFilterValue = params.filterValue;
929
+ } else {
930
+ if (view === "BOARD" && !selectedPipeline) {
931
+ mFilterValue = defaultPipelineId;
932
+ updateLink({
933
+ fV: defaultPipelineId
934
+ });
935
+ } else if (!excludedIds.includes(hubspotObjectTypeId)) {
936
+ mFilterValue = selectedPipeline || null;
937
+ } else {
938
+ mFilterValue = data.data.length === 1 ? defaultPipelineId : selectedPipeline;
939
+ }
940
+ }
941
+ set({ selectedPipeline: mFilterValue });
942
+ return mFilterValue;
943
+ },
944
+ setTableData: (response) => {
945
+ set({
946
+ tableData: response
947
+ });
948
+ },
949
+ setTablePrependData: async (response) => {
950
+ const state = get();
951
+ let rows = [];
952
+ if (response === "loading") {
953
+ const row = await state.tableData?.data?.results?.columns.reduce((acc, item) => {
954
+ if (!item.hidden) {
955
+ acc[item.key] = "loading";
956
+ }
957
+ return acc;
958
+ }, {});
959
+ rows = [row, ...state.tablePrependData];
960
+ } else {
961
+ const data = response?.data;
962
+ if (!data) {
963
+ set({
964
+ tablePrependData: []
965
+ });
966
+ }
967
+ const row = await Object.fromEntries(
968
+ Object.entries(data).map(([key, value]) => [
969
+ key,
970
+ value?.value ?? value
971
+ ])
972
+ );
973
+ rows = [...state.tablePrependData];
974
+ if (rows.length > 0) {
975
+ rows[0] = row;
976
+ } else {
977
+ rows.push(row);
978
+ }
979
+ }
980
+ set({
981
+ tablePrependData: rows
982
+ });
983
+ return rows;
984
+ }
985
+ }));
986
+ function useTable() {
987
+ const tableState = tableStore.getState();
988
+ return {
989
+ ...tableState,
990
+ ...{ listeners: { subscribe: tableStore.subscribe } }
991
+ };
992
+ }
993
+
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)
1009
+ );
1010
+ },
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 purgeCrmListCacheAfterCrmWrite / purgeCrmDetailAndListAfterCrmWrite. */
1042
+ setObjectsQueryParams(params) {
1043
+ tableStore2.setState({
1044
+ queryParams: params
1045
+ });
1046
+ },
1047
+ /** Called from Client.object.sideBarList — feeds post-write list purge for sidebarTable writes. */
1048
+ setMultiObjectsQueryParams(hubspotObjectTypeId, params) {
1049
+ if (!hubspotObjectTypeId) {
1050
+ return;
1051
+ }
1052
+ const state = tableStore2.getState();
1053
+ tableStore2.setState({
1054
+ multiObjectsQueryParams: {
1055
+ ...state.multiObjectsQueryParams,
1056
+ [String(hubspotObjectTypeId)]: params
1057
+ }
1058
+ });
1059
+ },
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
+ }
1104
+ }
1105
+ },
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));
1124
+ });
1125
+ return {
1126
+ ...prependStage,
1127
+ data: {
1128
+ ...prependStage.data,
1129
+ results: {
1130
+ ...prependStage.data?.results,
1131
+ rows: filteredRows
1132
+ }
1133
+ }
1134
+ };
1135
+ });
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))
1140
+ );
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));
1145
+ });
1146
+ }
1147
+ const hubspotObjectTypeId = payload?.hubspotObjectTypeId;
1148
+ const selectedPipeline = payload?.selectedPipeline;
1149
+ if (response?.data?.total < 1 || payload?.componentName) {
1150
+ newTablePrependData = [];
1151
+ }
1152
+ if (state.viewType && state.viewType != viewType) {
1153
+ newTablePrependData = [];
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
+ });
1170
+ },
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
+ }
1198
+ },
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
+ }
1319
+ }
1320
+ tableStore2.setState({
1321
+ tablePrependData: rows
1322
+ });
1323
+ }
1324
+ };
1325
+
1326
+ // src/store2/use-uploader.ts
1327
+ var uploaderStore = createStore2({
1328
+ attachments: []
1329
+ });
1330
+ function toAttachmentSummary(attachment) {
1331
+ return {
1332
+ createdAt: attachment.createdAt,
1333
+ id: attachment.id,
1334
+ name: attachment.name,
1335
+ size: attachment.size,
1336
+ type: attachment.type,
1337
+ updatedAt: attachment.updatedAt
1338
+ };
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
+ };
1360
+
1361
+ // src/store2/use-note.ts
1362
+ var noteStore = createStore2({
1363
+ notes: [],
1364
+ prependNotes: [],
1365
+ id: "",
1366
+ queryParams: null
1367
+ });
1368
+ var actions4 = {
1369
+ /** Called from Client.note.list — feeds purgeEngagementCaches (view: notes). */
1370
+ setListQueryParams(params) {
1371
+ noteStore.setState({
1372
+ queryParams: params
1373
+ });
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 = [];
1389
+ }
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: []
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;
1429
+ } else {
1430
+ rows.push(row);
1431
+ }
1432
+ }
1433
+ noteStore.setState({
1434
+ prependNotes: rows
1435
+ });
1436
+ },
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,
1494
+ data: {
1495
+ ...state.notes.data,
1496
+ results: {
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
+ )
1501
+ }
1502
+ }
1503
+ };
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;
1514
+ }
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 = [];
1547
+ }
1548
+ emailStore.setState({
1549
+ emails: response,
1550
+ prependEmails: newPrependEmails,
1551
+ id
1552
+ });
1553
+ },
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
+ });
1571
+ }
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
+ ];
1580
+ }
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
1593
+ });
1594
+ },
1595
+ clearPrependEmails() {
1596
+ emailStore.setState({
1597
+ prependEmails: []
1598
+ });
1599
+ actions3.clearAttachments();
1600
+ },
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
1658
+ )
1659
+ }
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
1666
+ );
1667
+ }
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, recordIds) {
1692
+ const target = {
1693
+ domain: "crm_object_data",
1694
+ objectTypeId,
1695
+ views: ["list"],
1696
+ listQuery: listQuery ?? { page: 1, limit: 10, view: "LIST" }
1697
+ };
1698
+ if (recordIds?.length) {
1699
+ target.recordIds = recordIds;
1700
+ }
1701
+ return target;
1702
+ }
1703
+ function buildCrmSinglePurgeTarget(objectTypeId, recordIds, listQuery) {
1704
+ return {
1705
+ domain: "crm_object_data",
1706
+ objectTypeId,
1707
+ views: ["single"],
1708
+ recordIds,
1709
+ listQuery
1710
+ };
1711
+ }
1712
+ function buildEngagementPurgeTarget(objectTypeId, recordIds, views, options) {
1713
+ if (!recordIds.length) {
1714
+ throw new Error("recordIds is required for engagement purge views");
1715
+ }
1716
+ const target = {
1717
+ domain: "crm_object_data",
1718
+ objectTypeId,
1719
+ recordIds,
1720
+ views,
1721
+ fileIds: options?.fileIds,
1722
+ listQuery: options?.listQuery ?? { page: 1, limit: 10 }
1723
+ };
1724
+ if (options?.engagementItemIds?.length) {
1725
+ target.engagementItemIds = options.engagementItemIds;
1726
+ }
1727
+ return target;
1728
+ }
1729
+ function buildUserSessionPurgeTarget() {
1730
+ return { domain: "user_session" };
1731
+ }
1732
+ function buildPortalConfigPurgeTarget(objectTypeIds) {
1733
+ return {
1734
+ domain: "portal_object_config",
1735
+ objectTypeIds
1736
+ };
1737
+ }
1738
+ function mergePurgeTargets(...targets) {
1739
+ return targets;
1740
+ }
1741
+ function buildCachePurgeRequest(targets, options) {
1742
+ const request = {
1743
+ mode: options?.mode ?? "soft",
1744
+ warm: options?.warm ?? true,
1745
+ includeContactAccess: options?.includeContactAccess ?? true,
1746
+ includeShortOnHard: options?.includeShortOnHard ?? false,
1747
+ confirmPortalWide: options?.confirmPortalWide ?? false,
1748
+ targets
1749
+ };
1750
+ if (options?.postCrmWrite) {
1751
+ request.postCrmWrite = true;
1752
+ }
1753
+ if (options?.warmListDelayMs != null) {
1754
+ request.warmListDelayMs = options.warmListDelayMs;
1755
+ }
1756
+ return request;
1757
+ }
1758
+
1759
+ // src/utils/cache/createCachePurgeJob.ts
1760
+ function randomIdempotencyKey() {
1761
+ if (typeof crypto !== "undefined" && crypto.randomUUID) {
1762
+ return crypto.randomUUID();
1763
+ }
1764
+ return `purge-${Date.now()}-${Math.random().toString(36).slice(2)}`;
1765
+ }
1766
+ function mapErrorCode(status, message) {
1767
+ if (status === 400 || status === 422) {
1768
+ return "VALIDATION";
1769
+ }
1770
+ if (status === 429) {
1771
+ return "RATE_LIMITED";
1772
+ }
1773
+ if (message?.toLowerCase().includes("disabled")) {
1774
+ return "PURGE_API_DISABLED";
1775
+ }
1776
+ return status ? "UNKNOWN" : "NETWORK";
1777
+ }
1778
+ function sleep(ms) {
1779
+ return new Promise((resolve) => setTimeout(resolve, ms));
1780
+ }
1781
+ async function createCachePurgeJob(request, options = {}) {
1782
+ const idempotencyKey = options.idempotencyKey ?? randomIdempotencyKey();
1783
+ try {
1784
+ const headers = { "Idempotency-Key": idempotencyKey };
1785
+ const response = await Client.cache.purge(
1786
+ request,
1787
+ headers
1788
+ );
1789
+ const data = response?.data;
1790
+ const purgeJobId = data?.purgeJobId;
1791
+ let status = data?.status;
1792
+ if (options.waitForWarm && purgeJobId && request.warm !== false) {
1793
+ const timeout = options.pollTimeoutMs ?? 3e4;
1794
+ const interval = options.pollIntervalMs ?? 500;
1795
+ const deadline = Date.now() + timeout;
1796
+ while (Date.now() < deadline) {
1797
+ const statusRes = await Client.cache.purgeStatus(purgeJobId);
1798
+ const job = statusRes?.data;
1799
+ const jobStatus = job?.status;
1800
+ if (jobStatus === "completed") {
1801
+ status = "completed";
1802
+ break;
1803
+ }
1804
+ if (jobStatus === "failed") {
1805
+ return {
1806
+ ok: false,
1807
+ purgeJobId,
1808
+ status: "failed",
1809
+ errorCode: "WARM_FAILED",
1810
+ message: "Cache warm job failed"
1811
+ };
1812
+ }
1813
+ await sleep(interval);
1814
+ }
1815
+ if (status !== "completed") {
1816
+ return {
1817
+ ok: false,
1818
+ purgeJobId,
1819
+ status: status ?? "warming",
1820
+ errorCode: "WARM_FAILED",
1821
+ message: "Timed out waiting for cache warm job"
1822
+ };
1823
+ }
1824
+ }
1825
+ return {
1826
+ ok: true,
1827
+ purgeJobId,
1828
+ status,
1829
+ evicted: data?.evicted,
1830
+ warnings: data?.warnings
1831
+ };
1832
+ } catch (err) {
1833
+ const axiosErr = err;
1834
+ const status = axiosErr.response?.status;
1835
+ const message = axiosErr.response?.data?.message ?? (err instanceof Error ? err.message : "Cache purge request failed");
1836
+ return {
1837
+ ok: false,
1838
+ errorCode: mapErrorCode(status, message),
1839
+ message
1840
+ };
1841
+ }
1842
+ }
1843
+
1844
+ // src/utils/cache/crmCacheRefresh.ts
1845
+ async function purgeCrmObjectDataCache(options) {
1846
+ const result = await purgeCrmListCache(options);
1847
+ return result.ok;
1848
+ }
1849
+ async function purgeCrmListCacheAfterCrmWrite(options) {
1850
+ return purgeCrmListCache({
1851
+ ...options,
1852
+ postCrmWrite: true
1853
+ });
1854
+ }
1855
+ async function purgeCrmDetailAndListAfterCrmWrite(options) {
1856
+ const objectTypeId = options.objectTypeId?.trim();
1857
+ if (!objectTypeId || !options.recordIds?.length) {
1858
+ return {
1859
+ ok: false,
1860
+ errorCode: "VALIDATION",
1861
+ message: "objectTypeId and recordIds are required"
1862
+ };
1863
+ }
1864
+ return purgeCrmCombined({
1865
+ ...options,
1866
+ postCrmWrite: true,
1867
+ targets: mergePurgeTargets(
1868
+ buildCrmListPurgeTarget(objectTypeId, options.listQuery, options.recordIds),
1869
+ buildCrmSinglePurgeTarget(objectTypeId, options.recordIds, options.listQuery)
1870
+ )
1871
+ });
1872
+ }
1873
+ async function purgeCrmListCache(options) {
1874
+ const objectTypeId = options.objectTypeId?.trim();
1875
+ if (!objectTypeId) {
1876
+ return { ok: false, errorCode: "VALIDATION", message: "objectTypeId is required" };
1877
+ }
1878
+ const target = buildCrmListPurgeTarget(
1879
+ objectTypeId,
1880
+ options.listQuery,
1881
+ options.recordIds
1882
+ );
1883
+ const request = buildCachePurgeRequest([target], {
1884
+ mode: options.mode,
1885
+ warm: options.warm,
1886
+ postCrmWrite: options.postCrmWrite,
1887
+ warmListDelayMs: options.warmListDelayMs
1888
+ });
1889
+ return createCachePurgeJob(request, {
1890
+ idempotencyKey: options.idempotencyKey,
1891
+ waitForWarm: options.waitForWarm
1892
+ });
1893
+ }
1894
+ async function purgeCrmRecordCache(options) {
1895
+ const objectTypeId = options.objectTypeId?.trim();
1896
+ if (!objectTypeId || !options.recordIds?.length) {
1897
+ return {
1898
+ ok: false,
1899
+ errorCode: "VALIDATION",
1900
+ message: "objectTypeId and recordIds are required"
1901
+ };
1902
+ }
1903
+ const target = buildCrmSinglePurgeTarget(
1904
+ objectTypeId,
1905
+ options.recordIds,
1906
+ options.listQuery
1907
+ );
1908
+ const request = buildCachePurgeRequest([target], {
1909
+ mode: options.mode,
1910
+ warm: options.warm,
1911
+ postCrmWrite: options.postCrmWrite,
1912
+ warmListDelayMs: options.warmListDelayMs
1913
+ });
1914
+ return createCachePurgeJob(request, {
1915
+ idempotencyKey: options.idempotencyKey,
1916
+ waitForWarm: options.waitForWarm
1917
+ });
1918
+ }
1919
+ async function purgeEngagementCaches(options) {
1920
+ return purgeEngagementCachesInternal(options);
1921
+ }
1922
+ async function purgeEngagementCachesAfterCrmWrite(options) {
1923
+ return purgeEngagementCachesInternal({
1924
+ ...options,
1925
+ postCrmWrite: true
1926
+ });
1927
+ }
1928
+ async function purgeEngagementCachesInternal(options) {
1929
+ const objectTypeId = options.objectTypeId?.trim();
1930
+ if (!objectTypeId || !options.recordIds?.length || !options.views?.length) {
1931
+ return {
1932
+ ok: false,
1933
+ errorCode: "VALIDATION",
1934
+ message: "objectTypeId, recordIds, and views are required"
1935
+ };
1936
+ }
1937
+ const target = buildEngagementPurgeTarget(
1938
+ objectTypeId,
1939
+ options.recordIds,
1940
+ options.views,
1941
+ {
1942
+ fileIds: options.fileIds,
1943
+ listQuery: options.listQuery,
1944
+ engagementItemIds: options.engagementItemIds
1945
+ }
1946
+ );
1947
+ const request = buildCachePurgeRequest([target], {
1948
+ mode: options.mode,
1949
+ warm: options.warm,
1950
+ postCrmWrite: options.postCrmWrite,
1951
+ warmListDelayMs: options.warmListDelayMs
1952
+ });
1953
+ return createCachePurgeJob(request, {
1954
+ idempotencyKey: options.idempotencyKey,
1955
+ waitForWarm: options.waitForWarm
1956
+ });
1957
+ }
1958
+ async function purgeCrmCombined(options) {
1959
+ const request = buildCachePurgeRequest(options.targets, {
1960
+ mode: options.mode,
1961
+ warm: options.warm,
1962
+ postCrmWrite: options.postCrmWrite,
1963
+ warmListDelayMs: options.warmListDelayMs
1964
+ });
1965
+ return createCachePurgeJob(request, {
1966
+ idempotencyKey: options.idempotencyKey,
1967
+ waitForWarm: options.waitForWarm
1968
+ });
1969
+ }
1970
+
1971
+ // src/utils/cache/extractHubspotRecordIdFromWriteResponse.ts
1972
+ function extractHubspotRecordIdFromWriteResponse(response) {
1973
+ if (response == null || typeof response !== "object") {
1974
+ return void 0;
1975
+ }
1976
+ const root = response;
1977
+ const data = root.data;
1978
+ if (data != null && typeof data === "object") {
1979
+ const fromData = idFromRecordPayload(data);
1980
+ if (fromData) {
1981
+ return fromData;
1982
+ }
1983
+ }
1984
+ return idFromRecordPayload(root);
1985
+ }
1986
+ function idFromRecordPayload(payload) {
1987
+ const id = payload.id;
1988
+ if (id !== void 0 && id !== null && String(id).length > 0) {
1989
+ return String(id);
1990
+ }
1991
+ const hsObjectId = payload.hs_object_id;
1992
+ if (hsObjectId !== void 0 && hsObjectId !== null && String(hsObjectId).length > 0) {
1993
+ return String(hsObjectId);
1994
+ }
1995
+ return void 0;
1996
+ }
1997
+
1998
+ // src/utils/cache/extractEngagementItemIdFromWriteResponse.ts
1999
+ function extractEngagementItemIdFromWriteResponse(response) {
2000
+ if (response == null || typeof response !== "object") {
2001
+ return void 0;
2002
+ }
2003
+ const root = response;
2004
+ const candidates = [];
2005
+ const data = root.data;
2006
+ if (data != null && typeof data === "object") {
2007
+ const dataObj = data;
2008
+ candidates.push(dataObj);
2009
+ const nested = dataObj.response;
2010
+ if (nested != null && typeof nested === "object") {
2011
+ candidates.push(nested);
2012
+ }
2013
+ }
2014
+ const topResponse = root.response;
2015
+ if (topResponse != null && typeof topResponse === "object") {
2016
+ candidates.push(topResponse);
2017
+ }
2018
+ candidates.push(root);
2019
+ for (const payload of candidates) {
2020
+ const id = engagementIdFromPayload(payload);
2021
+ if (id) {
2022
+ return id;
2023
+ }
2024
+ }
2025
+ return void 0;
2026
+ }
2027
+ function engagementIdFromPayload(payload) {
2028
+ const fromHs = fieldValue(payload.hs_object_id);
2029
+ if (fromHs) {
2030
+ return fromHs;
2031
+ }
2032
+ const fromId = fieldValue(payload.id);
2033
+ if (fromId) {
2034
+ return fromId;
2035
+ }
2036
+ return void 0;
2037
+ }
2038
+ function fieldValue(raw) {
2039
+ if (raw == null) {
2040
+ return void 0;
2041
+ }
2042
+ if (typeof raw === "object") {
2043
+ const value = raw.value;
2044
+ if (value !== void 0 && value !== null && String(value).length > 0) {
2045
+ return String(value);
2046
+ }
2047
+ return void 0;
2048
+ }
2049
+ const s = String(raw);
2050
+ return s.length > 0 ? s : void 0;
2051
+ }
2052
+
2053
+ // src/utils/cache/resolveCrmListPurgeQuery.ts
2054
+ var LIST_QUERY_KEYS = [
2055
+ "sort",
2056
+ "search",
2057
+ "filterPropertyName",
2058
+ "filterOperator",
2059
+ "filterValue",
2060
+ "page",
2061
+ "limit",
2062
+ "view",
2063
+ "mediatorObjectTypeId",
2064
+ "mediatorObjectRecordId",
2065
+ "parentObjectTypeId",
2066
+ "parentObjectRecordId",
2067
+ "after"
2068
+ ];
2069
+ function toCachePurgeListQuery(raw) {
2070
+ if (!raw || typeof raw !== "object") {
2071
+ return { page: 1, limit: 10, view: "LIST" };
2072
+ }
2073
+ const q = {};
2074
+ for (const key of LIST_QUERY_KEYS) {
2075
+ const value = raw[key];
2076
+ if (value !== void 0 && value !== null && String(value).length > 0) {
2077
+ q[key] = String(value);
2078
+ }
2079
+ }
2080
+ if (raw.page !== void 0 && raw.page !== null) {
2081
+ const page = Number(raw.page);
2082
+ if (!Number.isNaN(page) && page > 0) {
2083
+ q.page = page;
2084
+ }
2085
+ }
2086
+ if (raw.limit !== void 0 && raw.limit !== null) {
2087
+ const limit = Number(raw.limit);
2088
+ if (!Number.isNaN(limit) && limit > 0) {
2089
+ q.limit = limit;
2090
+ }
2091
+ }
2092
+ const isPc = raw.isPrimaryCompany ?? raw.isPC;
2093
+ if (isPc !== void 0 && isPc !== null) {
2094
+ q.isPrimaryCompany = isPc === true || isPc === "true" || isPc === 1 || isPc === "1";
2095
+ }
2096
+ const view = raw.view;
2097
+ if (typeof view === "string") {
2098
+ q.view = view.toUpperCase() === "BOARD" ? "BOARD" : "LIST";
2099
+ }
2100
+ if (Object.keys(q).length === 0) {
2101
+ return { page: 1, limit: 10, view: "LIST" };
2102
+ }
2103
+ if (q.page === void 0) {
2104
+ q.page = 1;
2105
+ }
2106
+ if (q.limit === void 0) {
2107
+ q.limit = 10;
2108
+ }
2109
+ if (q.view === void 0) {
2110
+ q.view = "LIST";
2111
+ }
2112
+ return q;
2113
+ }
2114
+ function resolveCrmListPurgeQuery(options) {
2115
+ let raw;
2116
+ if (options.componentName === "sidebarTable" && options.hubspotObjectTypeId) {
2117
+ raw = options.multiObjectsQueryParams?.[String(options.hubspotObjectTypeId)] ?? null;
2118
+ } else {
2119
+ raw = options.tableQueryParams ?? null;
2120
+ }
2121
+ const base = toCachePurgeListQuery(raw ?? void 0);
2122
+ if (!options.writeContext || Object.keys(options.writeContext).length === 0) {
2123
+ return base;
2124
+ }
2125
+ return {
2126
+ ...base,
2127
+ ...options.writeContext
2128
+ };
2129
+ }
2130
+
2131
+ // src/client/index.ts
2132
+ var recordWriteContext = (paramsObject) => {
2133
+ if (!paramsObject) {
2134
+ return void 0;
2135
+ }
2136
+ const context = {};
2137
+ const keys = [
2138
+ "parentObjectTypeId",
2139
+ "parentObjectRecordId",
2140
+ "mediatorObjectTypeId",
2141
+ "mediatorObjectRecordId"
2142
+ ];
2143
+ keys.forEach((key) => {
2144
+ const value = paramsObject[key];
2145
+ if (value !== void 0 && value !== null && String(value).length > 0) {
2146
+ context[key] = String(value);
2147
+ }
2148
+ });
2149
+ return Object.keys(context).length > 0 ? context : void 0;
2150
+ };
2151
+ var triggerPostWriteListPurge = (props) => {
2152
+ const objectTypeId = props.hubspotObjectTypeId;
2153
+ if (!objectTypeId) {
2154
+ return;
2155
+ }
2156
+ const { queryParams, multiObjectsQueryParams } = tableStore2.getState();
2157
+ const listQuery = resolveCrmListPurgeQuery({
2158
+ componentName: props.componentName,
2159
+ hubspotObjectTypeId: objectTypeId,
2160
+ tableQueryParams: queryParams,
2161
+ multiObjectsQueryParams,
2162
+ writeContext: recordWriteContext(props.paramsObject)
2163
+ });
2164
+ const recordIds = props.recordId ? [String(props.recordId)] : void 0;
2165
+ purgeCrmListCacheAfterCrmWrite({
2166
+ objectTypeId: String(objectTypeId),
2167
+ listQuery,
2168
+ recordIds
2169
+ });
2170
+ };
2171
+ var mergeRecordWriteBody = (payload, paramsObject, options) => {
2172
+ const base = { ...payload || {} };
2173
+ const context = recordWriteContext(paramsObject);
2174
+ if (context) {
2175
+ base.context = context;
2176
+ }
2177
+ if (options && Object.keys(options).length > 0) {
2178
+ base.options = options;
2179
+ }
2180
+ return base;
2181
+ };
2182
+ var Client = {
2183
+ authentication: {
2184
+ preLogin: (data) => AuthHttpClient.post(API_ENDPOINTS.PRE_LOGIN, data),
2185
+ login: (data) => {
2186
+ const queryParams = config.hubId ? { hubId: config.hubId } : null;
2187
+ return AuthHttpClient.post(
2188
+ generateApiUrl({ route: API_ENDPOINTS.LOGIN, queryParams }),
2189
+ data,
2190
+ config?.devPortalId && {
2191
+ headers: {
2192
+ "X-Dev-Portal-Id": config.devPortalId
2193
+ }
2194
+ }
2195
+ );
2196
+ },
2197
+ verifyEmail: (data) => AuthHttpClient.post(API_ENDPOINTS.VERIFY_EMAIL, data),
2198
+ resetPasswordVerifyToken: (data) => AuthHttpClient.post(API_ENDPOINTS.RESET_PASSWORD_VERIFY_TOKEN, data),
2199
+ resetPassword: (data) => AuthHttpClient.post(API_ENDPOINTS.RESET_PASSWORD, data),
2200
+ forgetPassword: (data) => AuthHttpClient.post(API_ENDPOINTS.FORGET_PASSWORD, data),
2201
+ registerExistingUser: (data) => AuthHttpClient.post(API_ENDPOINTS.REGISTER_EXISTING_USER, data?.payload),
2202
+ verifyEmailResend: (data) => AuthHttpClient.post(API_ENDPOINTS.VERIFY_EMAIL_RESEND, data),
2203
+ resendEmail: (data) => AuthHttpClient.post(API_ENDPOINTS.RESEND_EMAIL, data),
2204
+ logout: () => HttpClient.post(API_ENDPOINTS.LOGOUT, null)
2205
+ },
2206
+ sso: {
2207
+ getSsoDetails: () => AuthHttpClient.get(API_ENDPOINTS.SSO_DETAILS),
2208
+ generateSsoUrl: (payload) => AuthHttpClient.get(generateApiUrl({ route: API_ENDPOINTS.SSO_URL, queryParams: payload?.queryParams })),
2209
+ ssoCallback: (payload) => AuthHttpClient.get(generateApiUrl({ route: API_ENDPOINTS.SSO_CALLBACK, queryParams: payload?.queryParams }))
2210
+ },
2211
+ user: {
2212
+ me: () => HttpClient.get(generateApiUrl({ route: API_ENDPOINTS.ME })),
2213
+ profile: (payload) => HttpClient.get(generateApiUrl({ route: API_ENDPOINTS.PROFILE, queryParams: payload })),
2214
+ changePassword: (data) => HttpClient.post(API_ENDPOINTS.CHANGE_PASSWORD, data)
2215
+ },
2216
+ pipeline: {
2217
+ list: (payload = null, param = null) => {
2218
+ const params = { hubspotObjectTypeId: payload?.hubspotObjectTypeId };
2219
+ const { getParamDetails: getParamDetails2 } = routeParam;
2220
+ const { paramsObject } = getParamDetails2({ type: payload?.componentName });
2221
+ const userData = getProfileData();
2222
+ const apiParams = {};
2223
+ if (paramsObject?.parentObjectTypeId) {
2224
+ apiParams.parentObjectTypeId = paramsObject?.parentObjectTypeId;
2225
+ } else if (payload?.isHome && userData?.data?.info?.objectTypeId && !param?.isPrimaryCompany) {
2226
+ apiParams.parentObjectTypeId = userData?.data?.info?.objectTypeId;
2227
+ } else if (payload?.isHome && userData?.data?.info?.objectTypeId && param?.isPrimaryCompany) {
2228
+ apiParams.parentObjectTypeId = "0-2";
2229
+ }
2230
+ apiParams.isPrimaryCompany = param?.isPrimaryCompany;
2231
+ apiParams.cache = payload?.cache;
2232
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.PIPELINES, params, queryParams: apiParams });
2233
+ return HttpClient.get(apiUrl);
2234
+ }
2235
+ },
2236
+ stage: {
2237
+ list: (props = null) => {
2238
+ const params = {
2239
+ // hubId: config.hubId,
2240
+ // portalId: portalId,
2241
+ objectTypeId: props?.params?.objectTypeId,
2242
+ pipelineId: props?.params?.pipelineId
2243
+ };
2244
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.STAGES, params });
2245
+ return HttpClient.get(apiUrl);
2246
+ }
2247
+ },
2248
+ object: {
2249
+ list: async (payload = null, param = null) => {
2250
+ const { setObjectsQueryParams } = actions2;
2251
+ const params = { hubspotObjectTypeId: payload?.hubspotObjectTypeId };
2252
+ const { updateLink, getLinkParams } = useUpdateLink();
2253
+ const { getParamDetails: getParamDetails2 } = routeParam;
2254
+ const { paramsObject, parentAccessLabel } = getParamDetails2({ type: payload?.componentName });
2255
+ const userData = getProfileData();
2256
+ const pipeline = payload?.variables?.pipeline;
2257
+ const mPipelines = payload?.variables?.mPipelines;
2258
+ const mSelectedPipeline = pipeline !== void 0 ? pipeline : payload?.selectedPipeline;
2259
+ if (mSelectedPipeline) {
2260
+ param.filterValue = mSelectedPipeline;
2261
+ } else if (payload?.specPipeLine && payload?.pipeLineId) {
2262
+ param.filterValue = payload?.pipeLineId;
2263
+ } else if (payload?.hubspotObjectTypeId != "0-3" || payload?.hubspotObjectTypeId != "0-5") {
2264
+ param.filterValue = "";
2265
+ }
2266
+ const fParams = getLinkParams();
2267
+ param = { ...payload?.isFristTimeLoadData && fParams && !payload?.isHome ? fParams : param, ...paramsObject };
2268
+ if (!payload?.isFristTimeLoadData || !fParams) {
2269
+ await updateLink({
2270
+ "sort": param?.sort,
2271
+ "s": param?.search,
2272
+ "fPn": param?.filterPropertyName,
2273
+ "fO": param?.filterOperator,
2274
+ "fV": param?.filterValue,
2275
+ // "c": param?.cache,
2276
+ "isPC": param?.isPrimaryCompany,
2277
+ "v": param?.view,
2278
+ "l": param?.limit,
2279
+ "p": param?.page,
2280
+ "a": param?.after
2281
+ });
2282
+ }
2283
+ if (mPipelines != void 0 && mPipelines?.length === 0 && !payload?.specPipeLine) {
2284
+ param.filterValue = "";
2285
+ await updateLink({
2286
+ "fV": param?.filterValue
2287
+ });
2288
+ }
2289
+ if (mPipelines != void 0 && mPipelines?.length === 1 && !payload?.specPipeLine && mSelectedPipeline != null) {
2290
+ param.filterValue = mPipelines[0].pipelineId;
2291
+ await updateLink({
2292
+ "fV": param?.filterValue
2293
+ });
2294
+ }
2295
+ if (payload?.isHome || payload?.hubspotObjectTypeId === "0-5" && payload?.componentName === "object") {
2296
+ let parentObjectTypeId = "";
2297
+ if (userData?.data?.info?.objectTypeId && !param?.isPrimaryCompany) {
2298
+ parentObjectTypeId = userData?.data?.info?.objectTypeId;
2299
+ } else if (userData?.data?.info?.objectTypeId && param?.isPrimaryCompany) {
2300
+ parentObjectTypeId = "0-2";
2301
+ }
2302
+ param.parentObjectTypeId = parentObjectTypeId;
2303
+ }
2304
+ param.parentAccessLabel = parentAccessLabel;
2305
+ const {
2306
+ stageId,
2307
+ nextPage
2308
+ } = useTable();
2309
+ if (stageId) {
2310
+ param.stageId = stageId;
2311
+ }
2312
+ if (param?.view === "BOARD") {
2313
+ param.page = nextPage;
2314
+ }
2315
+ setObjectsQueryParams(param);
2316
+ param.cache = payload?.cache;
2317
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.OBJECTS, params, queryParams: param });
2318
+ return HttpClient.get(apiUrl);
2319
+ },
2320
+ sideBarList: async (payload = null) => {
2321
+ const { setMultiObjectsQueryParams } = actions2;
2322
+ const hubspotObjectTypeId = payload?.hubspotObjectTypeId;
2323
+ const params = { hubspotObjectTypeId };
2324
+ const queryParams = payload.param;
2325
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.OBJECTS, params, queryParams });
2326
+ setMultiObjectsQueryParams(hubspotObjectTypeId, queryParams ?? {});
2327
+ return HttpClient.get(apiUrl);
2328
+ },
2329
+ form: (payload = null) => {
2330
+ const params = { hubspotObjectTypeId: payload?.hubspotObjectTypeId };
2331
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.OBJECTS_FORM, params, queryParams: payload?.params });
2332
+ return HttpClient.get(apiUrl);
2333
+ },
2334
+ objectFormOptions: (payload = null) => {
2335
+ const params = {
2336
+ formId: payload?.formId,
2337
+ objectTypeId: payload?.objectTypeId ?? payload?.hubspotObjectTypeId
2338
+ };
2339
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.OBJECTS_FORM_OPTIONS, params, queryParams: payload?.params });
2340
+ return HttpClient.get(apiUrl);
2341
+ },
2342
+ create: async (props = null) => {
2343
+ const { getParamDetails: getParamDetailsForCreate } = routeParam;
2344
+ const { paramsObject } = getParamDetailsForCreate({ type: props?.componentName });
2345
+ const cardParentMerge = props?.componentName === "association" ? true : false;
2346
+ const body = mergeRecordWriteBody(props?.payload, paramsObject, {
2347
+ cardParentMerge,
2348
+ addAnother: props?.params?.addAnother
2349
+ });
2350
+ const params = { hubspotObjectTypeId: props?.hubspotObjectTypeId };
2351
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.RECORDS_CREATE, params, queryParams: props?.params });
2352
+ const response = await HttpClient.post(apiUrl, body);
2353
+ triggerPostWriteListPurge({
2354
+ hubspotObjectTypeId: props?.hubspotObjectTypeId,
2355
+ componentName: props?.componentName,
2356
+ paramsObject,
2357
+ recordId: extractHubspotRecordIdFromWriteResponse(response)
2358
+ });
2359
+ return response;
2360
+ },
2361
+ createExisting: async (props = null) => {
2362
+ const { getParamDetails: getParamDetailsForAssociate } = routeParam;
2363
+ const { paramsObject } = getParamDetailsForAssociate({ type: props?.componentName });
2364
+ const { getLinkParams } = useUpdateLink();
2365
+ const fParams = getLinkParams();
2366
+ const queryParams = { ...fParams, ...props?.params };
2367
+ const params = {
2368
+ fromObjectTypeId: props?.fromObjectTypeId ?? props?.hubspotObjectTypeId,
2369
+ fromRecordId: props?.fromRecordId,
2370
+ toObjectTypeId: props?.toObjectTypeId
2371
+ };
2372
+ const payload = props.payload;
2373
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.RECORDS_ASSOCIATE, params, queryParams });
2374
+ const response = await HttpClient.post(apiUrl, payload);
2375
+ const objectTypeId = props?.toObjectTypeId ?? props?.hubspotObjectTypeId;
2376
+ const recordId = extractHubspotRecordIdFromWriteResponse(response) ?? (props?.fromRecordId != null ? String(props.fromRecordId) : void 0);
2377
+ triggerPostWriteListPurge({
2378
+ hubspotObjectTypeId: objectTypeId,
2379
+ componentName: props?.componentName,
2380
+ paramsObject,
2381
+ recordId
2382
+ });
2383
+ return response;
2384
+ },
2385
+ removeExisting: async (props = null) => {
2386
+ const { getParamDetails: getParamDetailsForRemove } = routeParam;
2387
+ const { paramsObject } = getParamDetailsForRemove({ type: props?.componentName });
2388
+ const body = mergeRecordWriteBody(props?.payload, paramsObject, void 0);
2389
+ const params = {
2390
+ fromObjectTypeId: props?.fromObjectTypeId ?? props?.hubspotObjectTypeId,
2391
+ fromRecordId: props?.fromRecordId,
2392
+ toObjectTypeId: props?.toObjectTypeId
2393
+ };
2394
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.RECORDS_DISASSOCIATE, params });
2395
+ const response = await HttpClient.delete(apiUrl, { data: body });
2396
+ const objectTypeId = props?.toObjectTypeId ?? props?.hubspotObjectTypeId;
2397
+ if (objectTypeId) {
2398
+ const { queryParams, multiObjectsQueryParams } = tableStore2.getState();
2399
+ const listQuery = resolveCrmListPurgeQuery({
2400
+ componentName: props?.componentName,
2401
+ hubspotObjectTypeId: objectTypeId,
2402
+ tableQueryParams: queryParams,
2403
+ multiObjectsQueryParams,
2404
+ writeContext: recordWriteContext(paramsObject)
2405
+ });
2406
+ purgeCrmListCache({
2407
+ objectTypeId: String(objectTypeId),
2408
+ listQuery
2409
+ });
2410
+ }
2411
+ return response;
2412
+ },
2413
+ details: (props = null) => {
2414
+ const { paramsObject: urlParam, parentAccessLabel } = getParamDetails("", true);
2415
+ const hubspotObjectTypeId = ticketHubspotObjectTypeId();
2416
+ const params = {
2417
+ // hubId: config.hubId,
2418
+ // portalId: portalId,
2419
+ objectId: props?.params?.objectId,
2420
+ id: props?.params?.id
2421
+ };
2422
+ const queryParams = {
2423
+ parentAccessLabel,
2424
+ ...props?.queryParams,
2425
+ ...urlParam
2426
+ };
2427
+ if (hubspotObjectTypeId) queryParams.parentObjectTypeId = hubspotObjectTypeId;
2428
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.OBJECTS_DETAILS, params, queryParams });
2429
+ return HttpClient.get(apiUrl);
2430
+ },
2431
+ update: async (props = null) => {
2432
+ const hubspotObjectTypeId = ticketHubspotObjectTypeId();
2433
+ const params = {
2434
+ objectId: props?.params?.objectId,
2435
+ id: props?.params?.id
2436
+ };
2437
+ const { getParamDetails: getParamDetailsForUpdate } = routeParam;
2438
+ const { paramsObject } = getParamDetailsForUpdate({ type: props?.componentName });
2439
+ const cardParentMerge = props?.componentName === "association" ? true : false;
2440
+ const rawPayload = props?.payload || {};
2441
+ const properties = rawPayload.properties ?? rawPayload.propertyPayload ?? rawPayload;
2442
+ const body = mergeRecordWriteBody(
2443
+ { properties },
2444
+ paramsObject,
2445
+ { cardParentMerge }
2446
+ );
2447
+ const queryParams = {};
2448
+ if (hubspotObjectTypeId) queryParams.parentObjectTypeId = hubspotObjectTypeId;
2449
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.RECORDS_UPDATE, params, queryParams });
2450
+ const { queryParams: tableQueryParams, multiObjectsQueryParams } = tableStore2.getState();
2451
+ const writeContext = recordWriteContext(paramsObject);
2452
+ const listQuery = resolveCrmListPurgeQuery({
2453
+ componentName: props?.componentName,
2454
+ hubspotObjectTypeId: props?.hubspotObjectTypeId ?? props?.params?.objectId,
2455
+ tableQueryParams,
2456
+ multiObjectsQueryParams,
2457
+ writeContext
2458
+ });
2459
+ const response = await HttpClient.put(apiUrl, body);
2460
+ const objectTypeId = props?.hubspotObjectTypeId ?? props?.params?.objectId;
2461
+ const recordId = props?.params?.id;
2462
+ if (objectTypeId && recordId) {
2463
+ purgeCrmDetailAndListAfterCrmWrite({
2464
+ objectTypeId: String(objectTypeId),
2465
+ recordIds: [String(recordId)],
2466
+ listQuery
2467
+ });
2468
+ } else if (objectTypeId) {
2469
+ triggerPostWriteListPurge({
2470
+ hubspotObjectTypeId: objectTypeId,
2471
+ componentName: props?.componentName,
2472
+ paramsObject
2473
+ });
2474
+ }
2475
+ return response;
2476
+ }
2477
+ },
2478
+ note: {
2479
+ list: (props = null) => {
2480
+ const { setListQueryParams } = actions4;
2481
+ setListQueryParams(props?.queryParams ?? {});
2482
+ const params = {
2483
+ // hubId: config.hubId,
2484
+ // portalId: portalId,
2485
+ objectId: props?.params?.objectId,
2486
+ id: props?.params?.id
2487
+ };
2488
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.NOTES, params, queryParams: props?.queryParams });
2489
+ return HttpClient.get(apiUrl);
2490
+ },
2491
+ create: async (props = null) => {
2492
+ const params = { hubspotObjectTypeId: props?.hubspotObjectTypeId, ...props.params };
2493
+ const queryParams = props.queryParams;
2494
+ const payload = props.payload;
2495
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.NOTES_CREATE, params, queryParams });
2496
+ const listQuery = toCachePurgeListQuery(noteStore.getState().queryParams ?? {});
2497
+ const response = await HttpClient.post(apiUrl, payload);
2498
+ const recordId = props?.params?.id;
2499
+ const objectTypeId = props?.params?.objectId;
2500
+ if (recordId && objectTypeId) {
2501
+ const engagementItemId = extractEngagementItemIdFromWriteResponse(response);
2502
+ purgeEngagementCachesAfterCrmWrite({
2503
+ objectTypeId,
2504
+ recordIds: [String(recordId)],
2505
+ views: ["notes"],
2506
+ listQuery,
2507
+ engagementItemIds: engagementItemId ? [engagementItemId] : void 0
2508
+ });
2509
+ }
2510
+ return response;
2511
+ },
2512
+ update: async (props = null) => {
2513
+ const params = {
2514
+ // hubId: config.hubId,
2515
+ // portalId: portalId,
2516
+ objectId: props?.params?.objectId,
2517
+ id: props?.params?.id,
2518
+ note_id: props?.params?.note_id
2519
+ };
2520
+ const { paramsObject: queryParams } = getParamDetails();
2521
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.NOTES_DETAILS_UPDATE, params, queryParams });
2522
+ const listQuery = toCachePurgeListQuery(noteStore.getState().queryParams ?? {});
2523
+ const response = await HttpClient.put(apiUrl, props.payload);
2524
+ const recordId = props?.params?.id;
2525
+ const objectTypeId = props?.params?.objectId;
2526
+ const noteId = props?.params?.note_id;
2527
+ if (recordId && objectTypeId) {
2528
+ const engagementItemId = extractEngagementItemIdFromWriteResponse(response) ?? (noteId != null && String(noteId).length > 0 ? String(noteId) : void 0);
2529
+ purgeEngagementCachesAfterCrmWrite({
2530
+ objectTypeId,
2531
+ recordIds: [String(recordId)],
2532
+ views: ["notes"],
2533
+ listQuery,
2534
+ engagementItemIds: engagementItemId ? [engagementItemId] : void 0
2535
+ });
2536
+ }
2537
+ return response;
2538
+ },
2539
+ image: (props = null) => {
2540
+ const params = { hubspotObjectTypeId: props?.hubspotObjectTypeId, ...props.params };
2541
+ const queryParams = props.queryParams;
2542
+ const payload = props.payload;
2543
+ const axiosConfig = props.config || {};
2544
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.NOTES_IMAGE_UPLOAD, params, queryParams });
2545
+ return HttpClient.post(apiUrl, payload, {
2546
+ headers: {
2547
+ "Content-Type": "multipart/form-data"
2548
+ },
2549
+ ...axiosConfig
2550
+ });
2551
+ },
2552
+ attachment: (props = null) => {
2553
+ const params = { hubspotObjectTypeId: props?.hubspotObjectTypeId, ...props.params };
2554
+ const queryParams = props.queryParams;
2555
+ const payload = props.payload;
2556
+ const axiosConfig = props.config || {};
2557
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.NOTES_ATTACHMENT_UPLOAD, params, queryParams });
2558
+ return HttpClient.post(apiUrl, payload, {
2559
+ headers: {
2560
+ "Content-Type": "multipart/form-data"
2561
+ },
2562
+ ...axiosConfig
2563
+ });
2564
+ }
2565
+ },
2566
+ email: {
2567
+ list: (props = null) => {
2568
+ const { setListQueryParams } = actions5;
2569
+ setListQueryParams(props?.queryParams ?? {});
2570
+ const params = {
2571
+ // hubId: config.hubId,
2572
+ // portalId: portalId,
2573
+ objectId: props?.params?.objectId,
2574
+ id: props?.params?.id
2575
+ };
2576
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.EMAILS, params, queryParams: props?.queryParams });
2577
+ return HttpClient.get(apiUrl);
2578
+ },
2579
+ create: async (props = null) => {
2580
+ const params = { hubspotObjectTypeId: props?.hubspotObjectTypeId, ...props.params };
2581
+ const queryParams = props.queryParams;
2582
+ const payload = props.payload;
2583
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.EMAILS_CREATE, params, queryParams });
2584
+ const listQuery = toCachePurgeListQuery(emailStore.getState().queryParams ?? {});
2585
+ const response = await HttpClient.post(apiUrl, payload);
2586
+ const recordId = props?.params?.id;
2587
+ const objectTypeId = props?.params?.objectId;
2588
+ if (recordId && objectTypeId) {
2589
+ const engagementItemId = extractEngagementItemIdFromWriteResponse(response);
2590
+ purgeEngagementCachesAfterCrmWrite({
2591
+ objectTypeId,
2592
+ recordIds: [String(recordId)],
2593
+ views: ["emails"],
2594
+ listQuery,
2595
+ engagementItemIds: engagementItemId ? [engagementItemId] : void 0
2596
+ });
2597
+ }
2598
+ return response;
2599
+ },
2600
+ update: async (props = null) => {
2601
+ const params = {
2602
+ // hubId: config.hubId,
2603
+ // portalId: portalId,
2604
+ objectId: props?.params?.objectId,
2605
+ id: props?.params?.id,
2606
+ email_id: props?.params?.email_id ?? props?.params?.note_id
2607
+ };
2608
+ const { paramsObject: queryParams } = getParamDetails();
2609
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.EMAILS_DETAILS_UPDATE, params, queryParams });
2610
+ const listQuery = toCachePurgeListQuery(emailStore.getState().queryParams ?? {});
2611
+ const response = await HttpClient.put(apiUrl, props.payload);
2612
+ const recordId = props?.params?.id;
2613
+ const objectTypeId = props?.params?.objectId;
2614
+ const emailId = props?.params?.email_id ?? props?.params?.note_id;
2615
+ if (recordId && objectTypeId) {
2616
+ const engagementItemId = extractEngagementItemIdFromWriteResponse(response) ?? (emailId != null && String(emailId).length > 0 ? String(emailId) : void 0);
2617
+ purgeEngagementCachesAfterCrmWrite({
2618
+ objectTypeId,
2619
+ recordIds: [String(recordId)],
2620
+ views: ["emails"],
2621
+ listQuery,
2622
+ engagementItemIds: engagementItemId ? [engagementItemId] : void 0
2623
+ });
2624
+ }
2625
+ return response;
2626
+ },
2627
+ image: (props = null) => {
2628
+ const params = { hubspotObjectTypeId: props?.hubspotObjectTypeId, ...props.params };
2629
+ const queryParams = props.queryParams;
2630
+ const payload = props.payload;
2631
+ const axiosConfig = props.config || {};
2632
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.EMAILS_IMAGE_UPLOAD, params, queryParams });
2633
+ return HttpClient.post(apiUrl, payload, {
2634
+ headers: {
2635
+ "Content-Type": "multipart/form-data"
2636
+ },
2637
+ ...axiosConfig
2638
+ });
2639
+ },
2640
+ attachment: (props = null) => {
2641
+ const params = { hubspotObjectTypeId: props?.hubspotObjectTypeId, ...props.params };
2642
+ const queryParams = props.queryParams;
2643
+ const payload = props.payload;
2644
+ const axiosConfig = props.config || {};
2645
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.EMAILS_ATTACHMENT_UPLOAD, params, queryParams });
2646
+ return HttpClient.post(apiUrl, payload, {
2647
+ headers: {
2648
+ "Content-Type": "multipart/form-data"
2649
+ },
2650
+ ...axiosConfig
2651
+ });
2652
+ }
2653
+ },
2654
+ cache: {
2655
+ purge: (body, headers) => {
2656
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.CACHE_PURGE });
2657
+ return HttpClient.post(apiUrl, body, headers ? { headers } : void 0);
2658
+ },
2659
+ purgeStatus: (purgeJobId) => {
2660
+ const apiUrl = generateApiUrl({
2661
+ route: API_ENDPOINTS.CACHE_PURGE_STATUS,
2662
+ params: { purgeJobId }
2663
+ });
2664
+ return HttpClient.get(apiUrl);
2665
+ }
2666
+ },
2667
+ file: {
2668
+ list: (props = null) => {
2669
+ const { setListQueryParams } = actions6;
2670
+ setListQueryParams(props?.queryParams ?? {});
2671
+ const params = {
2672
+ // hubId: config.hubId,
2673
+ // portalId: portalId,
2674
+ objectId: props?.params?.objectId,
2675
+ id: props?.params?.id
2676
+ };
2677
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.FILES, params, queryParams: props?.queryParams });
2678
+ return HttpClient.get(apiUrl);
2679
+ },
2680
+ details: (props = null) => {
2681
+ const params = {
2682
+ // hubId: config.hubId,
2683
+ // portalId: portalId,
2684
+ objectId: props?.params?.objectId,
2685
+ id: props?.params?.id,
2686
+ rowId: props?.params?.rowId
2687
+ };
2688
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.FILE, params, queryParams: props?.queryParams });
2689
+ return HttpClient.get(apiUrl);
2690
+ },
2691
+ download: (props = null) => {
2692
+ const params = {
2693
+ objectId: props?.params?.objectId,
2694
+ id: props?.params?.id,
2695
+ rowId: props?.params?.rowId
2696
+ };
2697
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.FILE_DOWNLOAD, params, queryParams: props?.queryParams });
2698
+ return HttpClient.post(apiUrl, {});
2699
+ },
2700
+ addFolder: async (props = null) => {
2701
+ const params = { hubspotObjectTypeId: props?.hubspotObjectTypeId, ...props.params };
2702
+ const queryParams = props.queryParams;
2703
+ const payload = props.payload;
2704
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.FILES_CREATE_FOLDER, params, queryParams });
2705
+ const listQuery = fileStore.getState().queryParams ?? {};
2706
+ const response = await HttpClient.post(apiUrl, payload);
2707
+ const recordId = props?.params?.id;
2708
+ const objectTypeId = props?.params?.objectId;
2709
+ if (recordId && objectTypeId) {
2710
+ purgeEngagementCaches({
2711
+ objectTypeId,
2712
+ recordIds: [String(recordId)],
2713
+ views: ["files"],
2714
+ listQuery
2715
+ });
2716
+ }
2717
+ return response;
2718
+ },
2719
+ addFile: async (props = null) => {
2720
+ const params = { hubspotObjectTypeId: props?.hubspotObjectTypeId, ...props.params };
2721
+ const queryParams = props.queryParams;
2722
+ const payload = props.payload;
2723
+ const axiosConfig = props.config || {};
2724
+ const apiUrl = generateApiUrl({ route: API_ENDPOINTS.FILES_UPLOAD, params, queryParams });
2725
+ const listQuery = fileStore.getState().queryParams ?? {};
2726
+ const response = await HttpClient.post(apiUrl, payload, {
2727
+ headers: {
2728
+ "Content-Type": "multipart/form-data"
2729
+ },
2730
+ ...axiosConfig
2731
+ });
2732
+ const recordId = props?.params?.id;
2733
+ const objectTypeId = props?.params?.objectId;
2734
+ if (recordId && objectTypeId) {
2735
+ purgeEngagementCaches({
2736
+ objectTypeId,
2737
+ recordIds: [String(recordId)],
2738
+ views: ["files"],
2739
+ listQuery
2740
+ });
2741
+ }
2742
+ return response;
2743
+ }
2744
+ }
2745
+ };
2746
+
2747
+ // src/store2/use-sync.ts
2748
+ var syncStore = createStore2({
2749
+ apiSync: false,
2750
+ sync: false,
2751
+ isSyncLoading: false,
2752
+ isSyncDisable: false
2753
+ });
2754
+ var actions7 = {
2755
+ setIsSyncLoading(status) {
2756
+ syncStore.setState({
2757
+ isSyncLoading: status,
2758
+ sync: status
2759
+ });
2760
+ },
2761
+ setSync(status) {
2762
+ resetAllStore();
2763
+ syncStore.setState({
2764
+ isSyncLoading: status,
2765
+ sync: status
2766
+ });
2767
+ },
2768
+ setApiSync(status) {
2769
+ syncStore.setState({
2770
+ isSyncLoading: status,
2771
+ apiSync: status
2772
+ });
2773
+ },
2774
+ setSyncDisable(status) {
2775
+ syncStore.setState({
2776
+ isSyncDisable: status
2777
+ });
2778
+ }
2779
+ };
2780
+ var resetAllStore = () => {
2781
+ actions2.clearTablePrependData();
2782
+ actions4.clearPrependNotes();
2783
+ actions5.clearPrependEmails();
2784
+ };
2785
+
2786
+ // src/utils/logError.ts
2787
+ function logError(context, error) {
2788
+ if (axios.isAxiosError(error)) {
2789
+ resetAllStore();
2790
+ console.error(context, {
2791
+ message: error.message,
2792
+ status: error.response?.status,
2793
+ statusText: error.response?.statusText,
2794
+ data: error.response?.data,
2795
+ url: error.config?.url,
2796
+ method: error.config?.method
2797
+ });
2798
+ return;
2799
+ }
2800
+ if (error instanceof Error) {
2801
+ console.error(context, error.message, error);
2802
+ return;
2803
+ }
2804
+ console.error(context, error);
2805
+ }
2806
+
2807
+ // src/mutation/createMutation.ts
2808
+ function createMutation(mutationFn, options) {
2809
+ let inFlight = 0;
2810
+ let lastReportedLoading = null;
2811
+ const syncLoading = () => {
2812
+ const active = inFlight > 0;
2813
+ if (lastReportedLoading === active) return;
2814
+ lastReportedLoading = active;
2815
+ options?.onLoadingChange?.(active);
2816
+ };
2817
+ const mutate = async (payload) => {
2818
+ inFlight += 1;
2819
+ syncLoading();
2820
+ try {
2821
+ const response = await mutationFn(payload);
2822
+ await options?.onSuccess?.(response, payload);
2823
+ return response;
2824
+ } catch (error) {
2825
+ options?.onError?.(error, payload);
2826
+ logError("[mutation]", error);
2827
+ throw error;
2828
+ } finally {
2829
+ inFlight -= 1;
2830
+ syncLoading();
2831
+ }
2832
+ };
2833
+ return {
2834
+ mutate,
2835
+ isLoading: () => inFlight > 0
2836
+ };
2837
+ }
2838
+
2839
+ // src/apis/authentication.ts
2840
+ function preLogin(options) {
2841
+ const { mutate, isLoading } = createMutation(
2842
+ async (payload) => {
2843
+ const response = await Client.authentication.preLogin(payload);
2844
+ return response;
2845
+ },
2846
+ options
2847
+ );
2848
+ return {
2849
+ mutate,
2850
+ login: mutate,
2851
+ isLoading
2852
+ };
2853
+ }
2854
+ function login(options) {
2855
+ const { mutate, isLoading } = createMutation(
2856
+ async (payload) => {
2857
+ const response = await Client.authentication.login(payload);
2858
+ const tokenData = response?.data?.tokenData || {};
2859
+ const loggedInDetails = response?.data?.loggedInDetails || {};
2860
+ const currentPortal = response?.data?.loggedInDetails?.currentPortal || {};
2861
+ const currentPortalId = currentPortal?.portalId || null;
2862
+ const SubscriptionType = loggedInDetails?.subscriptionType || "BASIC";
2863
+ const token = tokenData?.token;
2864
+ const refreshToken = tokenData?.refreshToken;
2865
+ const expiresIn = tokenData?.expiresIn;
2866
+ const rExpiresIn = tokenData?.refreshExpiresIn;
2867
+ setPortal(currentPortal);
2868
+ setSubscriptionType(SubscriptionType);
2869
+ await setAccessToken(token, expiresIn);
2870
+ await setRefreshToken(refreshToken, rExpiresIn);
2871
+ await setLoggedInDetails(response.data);
2872
+ setConfig.setDevPortalId(currentPortalId);
2873
+ return response;
2874
+ },
2875
+ options
2876
+ );
2877
+ return {
2878
+ mutate,
2879
+ login: mutate,
2880
+ isLoading
2881
+ };
2882
+ }
2883
+ function verifyEmail(options) {
2884
+ const { mutate, isLoading } = createMutation(
2885
+ async (payload) => {
2886
+ const verifyEmailPayload = payload || {};
2887
+ const token = getParam("token");
2888
+ if (!verifyEmailPayload?.token) verifyEmailPayload.token = token;
2889
+ const response = await Client.authentication.verifyEmail(verifyEmailPayload);
2890
+ return response;
2891
+ },
2892
+ options
2893
+ );
2894
+ return {
2895
+ mutate,
2896
+ verifyEmail: mutate,
2897
+ isLoading
2898
+ };
2899
+ }
2900
+ function resetPasswordVerifyToken(options) {
2901
+ const { mutate, isLoading } = createMutation(
2902
+ async (payload) => {
2903
+ const resetPasswordVerifyTokenPayload = payload || {};
2904
+ const token = getParam("token");
2905
+ if (!resetPasswordVerifyTokenPayload?.token) resetPasswordVerifyTokenPayload.token = token;
2906
+ const response = await Client.authentication.resetPasswordVerifyToken(resetPasswordVerifyTokenPayload);
2907
+ return response;
2908
+ },
2909
+ options
2910
+ );
2911
+ return {
2912
+ mutate,
2913
+ resetPasswordVerifyToken: mutate,
2914
+ isLoading
2915
+ };
2916
+ }
2917
+ function resetPassword(options) {
2918
+ const { mutate, isLoading } = createMutation(
2919
+ async (payload) => {
2920
+ const response = await Client.authentication.resetPassword(payload);
2921
+ return response;
2922
+ },
2923
+ options
2924
+ );
2925
+ return {
2926
+ mutate,
2927
+ resetPassword: mutate,
2928
+ isLoading
2929
+ };
2930
+ }
2931
+ function forgetPassword(options) {
2932
+ const { mutate, isLoading } = createMutation(
2933
+ async (payload) => {
2934
+ const response = await Client.authentication.forgetPassword(payload);
2935
+ return response;
2936
+ },
2937
+ options
2938
+ );
2939
+ return {
2940
+ mutate,
2941
+ forgetPassword: mutate,
2942
+ isLoading
2943
+ };
2944
+ }
2945
+ function logout(options) {
2946
+ const { mutate, isLoading } = createMutation(
2947
+ async () => {
2948
+ const response = await Client.authentication.logout();
2949
+ clearAccessToken();
2950
+ removeAllCookie();
2951
+ return response;
2952
+ },
2953
+ options
2954
+ );
2955
+ return {
2956
+ mutate,
2957
+ logout: mutate,
2958
+ isLoading
2959
+ };
2960
+ }
2961
+ function registerExistingUser(options) {
2962
+ const { mutate, isLoading } = createMutation(
2963
+ async (payload) => {
2964
+ const response = await Client.authentication.registerExistingUser(payload);
2965
+ return response;
2966
+ },
2967
+ options
2968
+ );
2969
+ return {
2970
+ mutate,
2971
+ registerExistingUser: mutate,
2972
+ isLoading
2973
+ };
2974
+ }
2975
+ function verifyEmailResend(options) {
2976
+ const { mutate, isLoading } = createMutation(
2977
+ async (payload) => {
2978
+ const response = await Client.authentication.verifyEmailResend(payload);
2979
+ return response;
2980
+ },
2981
+ options
2982
+ );
2983
+ return {
2984
+ mutate,
2985
+ verifyEmailResend: mutate,
2986
+ isLoading
2987
+ };
2988
+ }
2989
+ function resendEmail(options) {
2990
+ const { mutate, isLoading } = createMutation(
2991
+ async (payload) => {
2992
+ const response = await Client.authentication.resendEmail(payload);
2993
+ return response;
2994
+ },
2995
+ options
2996
+ );
2997
+ return {
2998
+ mutate,
2999
+ resendEmail: mutate,
3000
+ isLoading
3001
+ };
3002
+ }
3003
+
3004
+ // src/apis/sso.ts
3005
+ function getSsoDetails(options) {
3006
+ const { mutate, isLoading } = createMutation(
3007
+ async () => {
3008
+ const response = await Client.sso.getSsoDetails();
3009
+ return response;
3010
+ },
3011
+ options
3012
+ );
3013
+ return {
3014
+ mutate,
3015
+ getSsoDetails: mutate,
3016
+ isLoading
3017
+ };
3018
+ }
3019
+ function generateSsoUrl(options) {
3020
+ const { mutate, isLoading } = createMutation(
3021
+ async (payload) => {
3022
+ const response = await Client.sso.generateSsoUrl(payload);
3023
+ return response;
3024
+ },
3025
+ options
3026
+ );
3027
+ return {
3028
+ mutate,
3029
+ generateSsoUrl: mutate,
3030
+ isLoading
3031
+ };
3032
+ }
3033
+ function ssoCallback(options) {
3034
+ const { mutate, isLoading } = createMutation(
3035
+ async (payload) => {
3036
+ const response = await Client.sso.ssoCallback(payload);
3037
+ return response;
3038
+ },
3039
+ options
3040
+ );
3041
+ return {
3042
+ mutate,
3043
+ ssoCallback: mutate,
3044
+ isLoading
3045
+ };
3046
+ }
3047
+
3048
+ // src/apis/users.ts
3049
+ function me(options) {
3050
+ const { mutate, isLoading } = createMutation(
3051
+ async () => {
3052
+ const response = await Client.user.me();
3053
+ return response;
3054
+ },
3055
+ options
3056
+ );
3057
+ return {
3058
+ mutate,
3059
+ me: mutate,
3060
+ isLoading
3061
+ };
3062
+ }
3063
+ function profile(options) {
3064
+ const { mutate, isLoading } = createMutation(
3065
+ async (paylaod) => {
3066
+ const response = await Client.user.profile(paylaod);
3067
+ setProfileData(response);
3068
+ return response;
3069
+ },
3070
+ options
3071
+ );
3072
+ return {
3073
+ mutate,
3074
+ profile: mutate,
3075
+ isLoading
3076
+ };
3077
+ }
3078
+ function changePassword(options) {
3079
+ const { mutate, isLoading } = createMutation(
3080
+ async (payload) => {
3081
+ const response = await Client.user.changePassword(payload);
3082
+ return response;
3083
+ },
3084
+ options
3085
+ );
3086
+ return {
3087
+ mutate,
3088
+ changePassword: mutate,
3089
+ isLoading
3090
+ };
3091
+ }
3092
+
3093
+ // src/apis/pipeline.ts
3094
+ function list(options) {
3095
+ const {
3096
+ getTableParam
3097
+ } = useTable();
3098
+ const { mutate, isLoading } = createMutation(
3099
+ async (payload) => {
3100
+ const param = await getTableParam(payload?.companyAsMediator);
3101
+ const response = await Client.pipeline.list(payload, param);
3102
+ return response;
3103
+ },
3104
+ options
3105
+ );
3106
+ return {
3107
+ mutate,
3108
+ getPipelines: mutate,
3109
+ isLoading
3110
+ };
3111
+ }
3112
+
3113
+ // src/apis/stage.ts
3114
+ function list2(options) {
3115
+ const { mutate, isLoading } = createMutation(
3116
+ async (payload) => {
3117
+ const response = await Client.stage.list(payload);
3118
+ return response;
3119
+ },
3120
+ options
3121
+ );
3122
+ return {
3123
+ mutate,
3124
+ getStages: mutate,
3125
+ isLoading
3126
+ };
3127
+ }
3128
+
3129
+ // src/store2/use-multi-object.ts
3130
+ var multiObjectStore = createStore2({
3131
+ objects: {},
3132
+ objectsPrependData: {},
3133
+ meta: {}
3134
+ });
3135
+ function getObjectKey(payload) {
3136
+ return String(payload?.hubspotObjectTypeId ?? "");
3137
+ }
3138
+ var actions8 = {
3139
+ setMultiObjectData(response, payload) {
3140
+ const key = getObjectKey(payload);
3141
+ const state = multiObjectStore.getState();
3142
+ const rows = response?.data?.results?.rows ?? [];
3143
+ const rowIds = new Set(
3144
+ rows.map((row) => row.id ?? row.hs_object_id).filter((id) => id != null && id !== "").map((id) => String(id))
3145
+ );
3146
+ let newPrependForKey = (state.objectsPrependData[key] ?? []).filter((item) => {
3147
+ const itemId = item.id ?? item.hs_object_id;
3148
+ if (itemId == null || itemId === "") return true;
3149
+ return !rowIds.has(String(itemId));
3150
+ });
3151
+ const selectedPipeline = payload?.selectedPipeline ?? "";
3152
+ const viewType = response?.info?.viewType ?? "";
3153
+ const prevMeta = state.meta[key];
3154
+ if (response?.data?.total < 1 || payload?.componentName) {
3155
+ newPrependForKey = [];
3156
+ }
3157
+ if (prevMeta?.viewType && prevMeta.viewType !== viewType) {
3158
+ newPrependForKey = [];
3159
+ }
3160
+ if (prevMeta?.selectedPipeline && prevMeta.selectedPipeline !== selectedPipeline) {
3161
+ newPrependForKey = [];
3162
+ }
3163
+ multiObjectStore.setState({
3164
+ objects: { ...state.objects, [key]: response },
3165
+ objectsPrependData: { ...state.objectsPrependData, [key]: newPrependForKey },
3166
+ meta: {
3167
+ ...state.meta,
3168
+ [key]: { selectedPipeline, viewType }
3169
+ }
3170
+ });
3171
+ },
3172
+ clearMultiObjectPrependData(hubspotObjectTypeId) {
3173
+ const state = multiObjectStore.getState();
3174
+ if (!hubspotObjectTypeId) {
3175
+ multiObjectStore.setState({ objectsPrependData: {} });
3176
+ return;
3177
+ }
3178
+ const key = String(hubspotObjectTypeId);
3179
+ const { [key]: _, ...rest } = state.objectsPrependData;
3180
+ multiObjectStore.setState({ objectsPrependData: rest });
3181
+ },
3182
+ async setMultiObjectPrependData(response, props) {
3183
+ const key = getObjectKey(props);
3184
+ const state = multiObjectStore.getState();
3185
+ const tableResponse = state.objects[key];
3186
+ let rows = state.objectsPrependData[key] ?? [];
3187
+ if (tableResponse?.data?.total > 1) {
3188
+ if (response === "loading") {
3189
+ const row = tableResponse?.data?.results?.columns.reduce(
3190
+ (acc, item) => {
3191
+ if (!item.hidden) {
3192
+ acc[item.key] = "loading";
3193
+ }
3194
+ return acc;
3195
+ },
3196
+ {}
3197
+ );
3198
+ rows = [row, ...rows];
3199
+ } else if (response?.data) {
3200
+ const data = response?.data;
3201
+ if (!data) {
3202
+ multiObjectStore.setState({
3203
+ objectsPrependData: { ...state.objectsPrependData, [key]: [] }
3204
+ });
3205
+ return;
3206
+ }
3207
+ const row = Object.fromEntries(
3208
+ Object.entries(data).map(([k, value]) => [k, value?.value ?? value])
3209
+ );
3210
+ rows = [...rows];
3211
+ if (rows.length > 0) {
3212
+ rows[0] = row;
3213
+ } else {
3214
+ rows.push(row);
3215
+ }
3216
+ }
3217
+ }
3218
+ multiObjectStore.setState({
3219
+ objectsPrependData: { ...state.objectsPrependData, [key]: rows }
3220
+ });
3221
+ }
3222
+ };
3223
+
3224
+ // src/apis/object.ts
3225
+ function list3(options) {
3226
+ const { getTableParam } = useTable();
3227
+ const { setObjectsData, setTableData } = actions2;
3228
+ const { mutate, isLoading } = createMutation(
3229
+ async (payload) => {
3230
+ const param = await getTableParam(payload?.companyAsMediator);
3231
+ const response = await Client.object.list(payload, param);
3232
+ await setObjectsData(response);
3233
+ await setTableData(response, payload);
3234
+ return response;
3235
+ },
3236
+ options
3237
+ );
3238
+ return {
3239
+ mutate,
3240
+ getObjects: mutate,
3241
+ isLoading
3242
+ };
3243
+ }
3244
+ function sideBarList(options) {
3245
+ const { setMultiObjectData } = actions8;
3246
+ const { mutate, isLoading } = createMutation(
3247
+ async (payload) => {
3248
+ const response = await Client.object.sideBarList(payload);
3249
+ setMultiObjectData(response, payload);
3250
+ return response;
3251
+ },
3252
+ options
3253
+ );
3254
+ return {
3255
+ mutate,
3256
+ getSideBarObjects: mutate,
3257
+ isLoading
3258
+ };
3259
+ }
3260
+ function form(options) {
3261
+ const { setFormData } = actions;
3262
+ const { mutate, isLoading } = createMutation(
3263
+ async (payload) => {
3264
+ const response = await Client.object.form(payload);
3265
+ setFormData(response);
3266
+ return response;
3267
+ },
3268
+ options
3269
+ );
3270
+ return {
3271
+ mutate,
3272
+ getObjectsForm: mutate,
3273
+ isLoading
3274
+ };
3275
+ }
3276
+ function objectFormOptions(options) {
3277
+ const { mutate, isLoading } = createMutation(
3278
+ async (payload) => {
3279
+ const response = await Client.object.objectFormOptions(payload);
3280
+ return response;
3281
+ },
3282
+ options
3283
+ );
3284
+ return {
3285
+ mutate,
3286
+ objectFormOptions: mutate,
3287
+ isLoading
3288
+ };
3289
+ }
3290
+ function create(options) {
3291
+ const { setTablePrependData } = actions2;
3292
+ const { setMultiObjectPrependData } = actions8;
3293
+ const { mutate, isLoading } = createMutation(
3294
+ async (props) => {
3295
+ if (props?.componentName === "sidebarTable") await setMultiObjectPrependData("loading", props);
3296
+ if (props?.componentName != "association" && props?.componentName != "sidebarTable") await setTablePrependData("loading", props);
3297
+ const response = await Client.object.create(props);
3298
+ if (props?.componentName === "sidebarTable") await setMultiObjectPrependData(response, props);
3299
+ if (props?.componentName != "association" && props?.componentName != "sidebarTable") await setTablePrependData(response, props);
3300
+ return response;
3301
+ },
3302
+ options
3303
+ );
3304
+ return {
3305
+ mutate,
3306
+ createObject: mutate,
3307
+ isLoading
3308
+ };
3309
+ }
3310
+ function createExisting(options) {
3311
+ const { mutate, isLoading } = createMutation(
3312
+ async (props) => {
3313
+ const response = await Client.object.createExisting(props);
3314
+ return response;
3315
+ },
3316
+ options
3317
+ );
3318
+ return {
3319
+ mutate,
3320
+ createExistingObject: mutate,
3321
+ isLoading
3322
+ };
3323
+ }
3324
+ function removeExisting(options) {
3325
+ const { mutate, isLoading } = createMutation(
3326
+ async (props) => {
3327
+ const response = await Client.object.removeExisting(props);
3328
+ return response;
3329
+ },
3330
+ options
3331
+ );
3332
+ return {
3333
+ mutate,
3334
+ removeExisting: mutate,
3335
+ isLoading
3336
+ };
3337
+ }
3338
+ function details(options) {
3339
+ const { mutate, isLoading } = createMutation(
3340
+ async (payload) => {
3341
+ const response = await Client.object.details(payload);
3342
+ return response;
3343
+ },
3344
+ options
3345
+ );
3346
+ return {
3347
+ mutate,
3348
+ getObjectsDetails: mutate,
3349
+ isLoading
3350
+ };
3351
+ }
3352
+ function update(options) {
3353
+ const { mutate, isLoading } = createMutation(
3354
+ async (payload) => {
3355
+ const response = await Client.object.update(payload);
3356
+ return response;
3357
+ },
3358
+ options
3359
+ );
3360
+ return {
3361
+ mutate,
3362
+ updateObjectsDetails: mutate,
3363
+ isLoading
3364
+ };
3365
+ }
3366
+
3367
+ // src/apis/note.ts
3368
+ function list4(options) {
3369
+ const { setNotes } = actions4;
3370
+ const { mutate, isLoading } = createMutation(
3371
+ async (payload) => {
3372
+ const response = await Client.note.list(payload);
3373
+ setNotes(response, payload);
3374
+ return response;
3375
+ },
3376
+ options
3377
+ );
3378
+ return {
3379
+ mutate,
3380
+ getNotes: mutate,
3381
+ isLoading
3382
+ };
3383
+ }
3384
+ function create2(options) {
3385
+ const { setPrependNote } = actions4;
3386
+ const { mutate, isLoading } = createMutation(
3387
+ async (props) => {
3388
+ await setPrependNote("loading");
3389
+ const response = await Client.note.create(props);
3390
+ await setPrependNote(response);
3391
+ return response;
3392
+ },
3393
+ options
3394
+ );
3395
+ return {
3396
+ mutate,
3397
+ createNote: mutate,
3398
+ isLoading
3399
+ };
3400
+ }
3401
+ function update2(options) {
3402
+ const { updatePrependNote } = actions4;
3403
+ const { mutate, isLoading } = createMutation(
3404
+ async (payload) => {
3405
+ const response = await Client.note.update(payload);
3406
+ return updatePrependNote(response);
3407
+ },
3408
+ options
3409
+ );
3410
+ return {
3411
+ mutate,
3412
+ updateNote: mutate,
3413
+ isLoading
3414
+ };
3415
+ }
3416
+
3417
+ // src/apis/email.ts
3418
+ function list5(options) {
3419
+ const { setEmails } = actions5;
3420
+ const { mutate, isLoading } = createMutation(
3421
+ async (payload) => {
3422
+ const response = await Client.email.list(payload);
3423
+ setEmails(response, payload);
3424
+ return response;
3425
+ },
3426
+ options
3427
+ );
3428
+ return {
3429
+ mutate,
3430
+ getEmails: mutate,
3431
+ isLoading
3432
+ };
3433
+ }
3434
+ function create3(options) {
3435
+ const { setPrependEmail } = actions5;
3436
+ const { mutate, isLoading } = createMutation(
3437
+ async (props) => {
3438
+ await setPrependEmail("loading");
3439
+ const response = await Client.email.create(props);
3440
+ await setPrependEmail(response);
3441
+ return response;
3442
+ },
3443
+ options
3444
+ );
3445
+ return {
3446
+ mutate,
3447
+ createEmail: mutate,
3448
+ isLoading
3449
+ };
3450
+ }
3451
+ function update3(options) {
3452
+ const { updatePrependEmail } = actions5;
3453
+ const { mutate, isLoading } = createMutation(
3454
+ async (payload) => {
3455
+ const response = await Client.email.update(payload);
3456
+ return updatePrependEmail(response);
3457
+ },
3458
+ options
3459
+ );
3460
+ return {
3461
+ mutate,
3462
+ updateEmail: mutate,
3463
+ isLoading
3464
+ };
3465
+ }
3466
+
3467
+ // src/apis/uploader.ts
3468
+ function imageUpload(options) {
3469
+ const { mutate, isLoading } = createMutation(
3470
+ async (payload) => {
3471
+ const response = payload?.type === "email" ? await Client.email.image(payload) : await Client.note.image(payload);
3472
+ return response;
3473
+ },
3474
+ options
3475
+ );
3476
+ return {
3477
+ mutate,
3478
+ imageUpload: mutate,
3479
+ isLoading
3480
+ };
3481
+ }
3482
+ function attachmentUpload(options) {
3483
+ const { mutate, isLoading } = createMutation(
3484
+ async (payload) => {
3485
+ const response = payload?.type === "email" ? await Client.email.attachment(payload) : await Client.note.attachment(payload);
3486
+ actions3.setAttachment(response);
3487
+ return response;
3488
+ },
3489
+ options
3490
+ );
3491
+ return {
3492
+ mutate,
3493
+ attachmentUpload: mutate,
3494
+ isLoading
3495
+ };
3496
+ }
3497
+
3498
+ // src/apis/file.ts
3499
+ function list6(options) {
3500
+ const { mutate, isLoading } = createMutation(
3501
+ async (payload) => {
3502
+ const response = await Client.file.list(payload);
3503
+ return response;
3504
+ },
3505
+ options
3506
+ );
3507
+ return {
3508
+ mutate,
3509
+ getFiles: mutate,
3510
+ isLoading
3511
+ };
3512
+ }
3513
+ function details2(options) {
3514
+ const { mutate, isLoading } = createMutation(
3515
+ async (payload) => {
3516
+ const response = await Client.file.details(payload);
3517
+ return response;
3518
+ },
3519
+ options
3520
+ );
3521
+ return {
3522
+ mutate,
3523
+ getFile: mutate,
3524
+ isLoading
3525
+ };
3526
+ }
3527
+ function addFolder(options) {
3528
+ const { mutate, isLoading } = createMutation(
3529
+ async (props) => {
3530
+ const response = await Client.file.addFolder(props);
3531
+ return response;
3532
+ },
3533
+ options
3534
+ );
3535
+ return {
3536
+ mutate,
3537
+ addFolder: mutate,
3538
+ isLoading
3539
+ };
3540
+ }
3541
+ function addFile(options) {
3542
+ const { mutate, isLoading } = createMutation(
3543
+ async (props) => {
3544
+ const response = await Client.file.addFile(props);
3545
+ return response;
3546
+ },
3547
+ options
3548
+ );
3549
+ return {
3550
+ mutate,
3551
+ addFile: mutate,
3552
+ isLoading
3553
+ };
3554
+ }
3555
+ function download(options) {
3556
+ const { mutate, isLoading } = createMutation(
3557
+ async (payload) => {
3558
+ const response = await Client.file.download(payload);
3559
+ return response;
3560
+ },
3561
+ options
3562
+ );
3563
+ return {
3564
+ mutate,
3565
+ downloadFile: mutate,
3566
+ isLoading
3567
+ };
3568
+ }
3569
+
3570
+ // src/apis/cache.ts
3571
+ function purge(options) {
3572
+ const { mutate, isLoading } = createMutation(
3573
+ async (payload) => {
3574
+ const safePayload = payload ?? {};
3575
+ const idempotencyKey = typeof safePayload.idempotencyKey === "string" ? safePayload.idempotencyKey : void 0;
3576
+ const headers = idempotencyKey ? { "Idempotency-Key": idempotencyKey } : void 0;
3577
+ const { idempotencyKey: _ignored, ...body } = safePayload;
3578
+ return Client.cache.purge(body, headers);
3579
+ },
3580
+ options
3581
+ );
3582
+ return { mutate, purgeCache: mutate, isLoading };
3583
+ }
3584
+ function purgeStatus(purgeJobId, options) {
3585
+ const { mutate, isLoading } = createMutation(
3586
+ async (jobId) => Client.cache.purgeStatus(jobId ?? purgeJobId),
3587
+ options
3588
+ );
3589
+ return {
3590
+ mutate,
3591
+ getPurgeStatus: () => mutate(purgeJobId),
3592
+ isLoading
3593
+ };
3594
+ }
3595
+
3596
+ // src/breadcrumb/breadcrumbs.ts
3597
+ var getBreadcrumbs = () => {
3598
+ const search = getParam("b");
3599
+ let breadcrumbs = decodeToBase64(search) || [];
3600
+ if (!breadcrumbs && breadcrumbs.length < 1) return [];
3601
+ const updated = breadcrumbs.map((breadcrumb, index) => {
3602
+ return generatePath(breadcrumbs, breadcrumb, index);
3603
+ });
3604
+ if (updated.length < 1) {
3605
+ const pathname = getPath();
3606
+ const routeMenu = getRouteMenu(pathname);
3607
+ return [
3608
+ {
3609
+ name: routeMenu?.title,
3610
+ path: routeMenu?.path
3611
+ }
3612
+ ];
3613
+ }
3614
+ return updated;
3615
+ };
3616
+ var getTableTitle = (componentName, title, ticketTableTitle) => {
3617
+ const search = getParam("b");
3618
+ let breadcrumbs = decodeToBase64(search) || [];
3619
+ if (breadcrumbs.length < 1) {
3620
+ const pathname = getPath();
3621
+ const routeMenu = getRouteMenu(pathname);
3622
+ breadcrumbs = [
3623
+ {
3624
+ n: routeMenu?.title,
3625
+ pt: routeMenu?.path
3626
+ }
3627
+ ];
3628
+ }
3629
+ let associatedtableTitleSingular = "";
3630
+ let tableTitle = "";
3631
+ let singularTableTitle = "";
3632
+ if (breadcrumbs && breadcrumbs.length > 0) {
3633
+ const lastItem = breadcrumbs[breadcrumbs.length - 1];
3634
+ const last = lastItem ? generatePath(breadcrumbs, lastItem, breadcrumbs.length - 1) : null;
3635
+ const previousItem = breadcrumbs[breadcrumbs.length - 2];
3636
+ const previous = previousItem ? generatePath(breadcrumbs, previousItem, breadcrumbs.length - 2) : null;
3637
+ const singularLastName = last?.name;
3638
+ associatedtableTitleSingular = singularLastName;
3639
+ if (componentName != "ticket") {
3640
+ tableTitle = previous?.name ? { last, previous } : { last };
3641
+ singularTableTitle = previous?.name ? `${singularLastName} with ${previous?.name}` : singularLastName;
3642
+ } else {
3643
+ const ticketTableTitleSingular = ticketTableTitle.endsWith("s") ? ticketTableTitle.slice(0, -1) : ticketTableTitle;
3644
+ tableTitle = { last: { name: title } };
3645
+ singularTableTitle = previous?.name ? `${ticketTableTitleSingular} with ${singularLastName} ` : ticketTableTitleSingular;
3646
+ }
3647
+ }
3648
+ return { associatedtableTitleSingular, tableTitle, singularTableTitle };
3649
+ };
3650
+ var getFormTitle = (type, title, activeTab) => {
3651
+ const search = getParam("b");
3652
+ let breadcrumbs = decodeToBase64(search) || [];
3653
+ if (breadcrumbs.length < 1) {
3654
+ const pathname = getPath();
3655
+ const routeMenu = getRouteMenu(pathname);
3656
+ breadcrumbs = [
3657
+ {
3658
+ n: routeMenu?.title,
3659
+ pt: routeMenu?.path
3660
+ }
3661
+ ];
3662
+ }
3663
+ let objectName = "";
3664
+ let puralObjectName = "";
3665
+ let dialogTitle = "";
3666
+ if (breadcrumbs && breadcrumbs?.length > 0) {
3667
+ const last = breadcrumbs[breadcrumbs?.length - 1];
3668
+ const lastName = last?.n;
3669
+ const mTitle = title;
3670
+ if (type === "association" && breadcrumbs && breadcrumbs?.length > 0) {
3671
+ objectName = title;
3672
+ puralObjectName = title;
3673
+ dialogTitle = `${activeTab == "addNew" ? `Create a new ${mTitle} for ${nameTrancate(lastName)}` : `Associate an Existing ${mTitle} with ${nameTrancate(lastName)}`}`;
3674
+ } else {
3675
+ const singularLastName = typeof lastName === "string" && lastName?.endsWith("s") ? lastName.slice(0, -1) : lastName;
3676
+ objectName = singularLastName;
3677
+ puralObjectName = lastName;
3678
+ dialogTitle = `${activeTab == "addNew" ? `Create a new ${mTitle?.includes("with") ? nameTrancate(mTitle?.replace("with", "for")) : nameTrancate(mTitle)}` : `Associate an Existing ${nameTrancate(mTitle)}`}`;
3679
+ }
3680
+ }
3681
+ return { objectName, puralObjectName, dialogTitle };
3682
+ };
3683
+ var nameTrancate = (name) => {
3684
+ return name?.length > 30 ? `${name?.slice(0, 30) + "..."}` : name;
3685
+ };
3686
+
3687
+ // src/breadcrumb/generate-url.ts
3688
+ var useMakeLink = () => {
3689
+ const search = getParam("b");
3690
+ const makeLink = (props) => {
3691
+ if (!search || "isPC" in props) {
3692
+ return buildParentRoute(props);
3693
+ } else {
3694
+ const breadcrumbItems = decodeToBase64(search) || [];
3695
+ return buildChildRoute(props, breadcrumbItems);
3696
+ }
3697
+ };
3698
+ return { makeLink };
3699
+ };
3700
+ var buildParentRoute = (props) => {
3701
+ const pathname = getPath();
3702
+ const routeMenu = getRouteMenu(pathname);
3703
+ const breadcrumbItems = [
3704
+ {
3705
+ n: routeMenu?.title,
3706
+ o_t_id: routeMenu?.path,
3707
+ isHome: props?.isHome || false
3708
+ }
3709
+ ];
3710
+ return buildChildRoute(props, breadcrumbItems);
3711
+ };
3712
+ var buildChildRoute = (props, breadcrumbItems) => {
3713
+ let breadcrumbs = [...breadcrumbItems];
3714
+ let breadcrumbType = breadcrumbStage(breadcrumbItems);
3715
+ if (props?.isHome && isMessingParentLastItem(breadcrumbItems)) {
3716
+ const parent = {
3717
+ n: props?.title || "",
3718
+ o_t_id: props?.objectTypeId,
3719
+ "pt": `/association/${props?.objectTypeId}`,
3720
+ isHome: props?.isHome || false,
3721
+ "prm": {
3722
+ "sort": "-hs_createdate",
3723
+ "s": "",
3724
+ "fPn": "hs_pipeline",
3725
+ "fO": "eq",
3726
+ "fV": "",
3727
+ "c": true,
3728
+ "isPC": props?.isPC,
3729
+ "v": "LIST",
3730
+ "l": "10",
3731
+ "p": 1
3732
+ }
3733
+ };
3734
+ breadcrumbs.push(parent);
3735
+ const newCrumb = {
3736
+ n: props?.name,
3737
+ o_t_id: props?.objectTypeId,
3738
+ o_r_id: props?.recordId
3739
+ };
3740
+ breadcrumbs.push(newCrumb);
3741
+ } else if (breadcrumbType === "root") {
3742
+ const newCrumb = {
3743
+ n: props?.name,
3744
+ o_t_id: props?.objectTypeId,
3745
+ o_r_id: props?.recordId
3746
+ };
3747
+ if (props?.isPC) {
3748
+ newCrumb.prm = {
3749
+ isPC: props?.isPC
3750
+ };
3751
+ }
3752
+ breadcrumbs.push(newCrumb);
3753
+ } else {
3754
+ const lastItem = breadcrumbs[breadcrumbs.length - 1];
3755
+ if (props?.objectTypeId != "0-5" && breadcrumbs.length > 2 && // check for only association ticket object
3756
+ (!isMessingParent(breadcrumbItems) && lastItem?.o_t_id === props?.objectTypeId) && // check for all associated object and check isMessingParent for skip parent to child and child to parent association data
3757
+ (props?.isHome && !isMessingParentLastItem(breadcrumbItems))) {
3758
+ const newCrumb = {
3759
+ n: props?.name,
3760
+ o_t_id: props?.objectTypeId,
3761
+ o_r_id: props?.recordId
3762
+ };
3763
+ if (props?.isPC) {
3764
+ newCrumb.prm = {
3765
+ isPC: props?.isPC
3766
+ };
3767
+ }
3768
+ breadcrumbs.push(newCrumb);
3769
+ } else {
3770
+ const lastItem2 = breadcrumbs[breadcrumbs.length - 1];
3771
+ const parent = {
3772
+ n: props?.associationLabel || props?.name,
3773
+ o_t_id: props?.objectTypeId
3774
+ };
3775
+ if (props?.tableParam) {
3776
+ parent.prm = props?.tableParam;
3777
+ }
3778
+ if (props?.defPermissions) {
3779
+ parent.dp = props?.defPermissions;
3780
+ }
3781
+ if (lastItem2?.o_t_id && lastItem2?.o_r_id) {
3782
+ breadcrumbs.push(parent);
3783
+ }
3784
+ if (props?.recordId) {
3785
+ const newCrumb = {
3786
+ n: props?.name,
3787
+ o_t_id: props?.objectTypeId,
3788
+ o_r_id: props?.recordId
3789
+ };
3790
+ if (props?.isPC) {
3791
+ newCrumb.prm = {
3792
+ isPC: props?.isPC
3793
+ };
3794
+ }
3795
+ breadcrumbs.push(newCrumb);
3796
+ }
3797
+ }
3798
+ }
3799
+ return generateUrl(props, breadcrumbs);
3800
+ };
3801
+
3802
+ // src/utils/datetime.ts
3803
+ var DEFAULT_HUBSPOT_TIMEZONE = "Asia/Kolkata";
3804
+ function getCurrentTimeZone() {
3805
+ try {
3806
+ return Intl.DateTimeFormat().resolvedOptions().timeZone || DEFAULT_HUBSPOT_TIMEZONE;
3807
+ } catch {
3808
+ return DEFAULT_HUBSPOT_TIMEZONE;
3809
+ }
3810
+ }
3811
+ function normalizeToTimestamp(value) {
3812
+ if (value == null || value === "") return null;
3813
+ if (typeof value === "number") {
3814
+ return value > 1e11 ? value : null;
3815
+ }
3816
+ if (typeof value === "string" && /^\d+$/.test(value)) {
3817
+ const n = Number(value);
3818
+ return n > 1e11 ? n : null;
3819
+ }
3820
+ if (typeof value === "string" || value instanceof Date) {
3821
+ const date = new Date(value);
3822
+ return Number.isNaN(date.getTime()) ? null : date.getTime();
3823
+ }
3824
+ return null;
3825
+ }
3826
+ function formatGmtOffset(timeZone = getCurrentTimeZone(), date = /* @__PURE__ */ new Date()) {
3827
+ const raw = new Intl.DateTimeFormat("en-US", {
3828
+ timeZone,
3829
+ timeZoneName: "longOffset"
3830
+ }).formatToParts(date).find((part) => part.type === "timeZoneName")?.value;
3831
+ if (!raw) return "";
3832
+ return raw.replace(/GMT([+-])0(\d)(?=:)/, "GMT$1$2");
3833
+ }
3834
+ function formatHubSpotActivityDateTimeParts(timestamp, timeZone = getCurrentTimeZone()) {
3835
+ const ms = normalizeToTimestamp(timestamp);
3836
+ if (ms == null) return null;
3837
+ const date = new Date(ms);
3838
+ const datePart = new Intl.DateTimeFormat("en-US", {
3839
+ timeZone,
3840
+ month: "long",
3841
+ day: "numeric",
3842
+ year: "numeric"
3843
+ }).format(date);
3844
+ const timePart = new Intl.DateTimeFormat("en-US", {
3845
+ timeZone,
3846
+ hour: "numeric",
3847
+ minute: "2-digit",
3848
+ hour12: true
3849
+ }).format(date);
3850
+ const gmtOffset = formatGmtOffset(timeZone, date);
3851
+ return {
3852
+ date: datePart,
3853
+ time: timePart,
3854
+ gmtOffset,
3855
+ formatted: `${datePart} at ${timePart} ${gmtOffset}`.trim()
3856
+ };
3857
+ }
3858
+ function formatHubSpotActivityDateTime(timestamp, timeZone = getCurrentTimeZone()) {
3859
+ return formatHubSpotActivityDateTimeParts(timestamp, timeZone)?.formatted ?? "";
3860
+ }
3861
+
3862
+ // src/index.ts
3863
+ var api = {
3864
+ preLogin,
3865
+ login,
3866
+ verifyEmail,
3867
+ resetPasswordVerifyToken,
3868
+ resetPassword,
3869
+ registerExistingUser,
3870
+ verifyEmailResend,
3871
+ resendEmail,
3872
+ getSsoDetails,
3873
+ generateSsoUrl,
3874
+ ssoCallback,
3875
+ forgetPassword,
3876
+ logout,
3877
+ me,
3878
+ profile,
3879
+ changePassword,
3880
+ pipelines: list,
3881
+ stages: list2,
3882
+ objects: list3,
3883
+ sideBarObjects: sideBarList,
3884
+ objectsForm: form,
3885
+ createObject: create,
3886
+ createExistingObject: createExisting,
3887
+ removeExistingObject: removeExisting,
3888
+ objectsDetails: details,
3889
+ updateObjectsDetails: update,
3890
+ objectFormOptions,
3891
+ notes: list4,
3892
+ createNote: create2,
3893
+ updateNote: update2,
3894
+ emails: list5,
3895
+ createEmail: create3,
3896
+ updateEmail: update3,
3897
+ imageUpload,
3898
+ attachmentUpload,
3899
+ files: list6,
3900
+ file: details2,
3901
+ fileDownload: download,
3902
+ addFolder,
3903
+ addFile,
3904
+ purgeCache: purge,
3905
+ cachePurgeStatus: purgeStatus,
3906
+ getRefreshToken,
3907
+ getAuthRefreshToken,
3908
+ isCookieExpired,
3909
+ isExpiresAccessToken,
3910
+ isAuthenticateApp,
3911
+ getAccessToken
3912
+ };
3913
+ var store = {
3914
+ storage,
3915
+ useTable
3916
+ };
3917
+ var breadcrumbsDetails = {
3918
+ getBreadcrumbs,
3919
+ getTableTitle,
3920
+ getFormTitle
3921
+ };
3922
+ var url = {
3923
+ useMakeLink,
3924
+ useUpdateLink
3925
+ };
3926
+ var routeParam = {
3927
+ getRouteDetails,
3928
+ getParamDetails
3929
+ };
3930
+
3931
+ 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, extractEngagementItemIdFromWriteResponse, extractHubspotRecordIdFromWriteResponse, formatGmtOffset, formatHubSpotActivityDateTime, formatHubSpotActivityDateTimeParts, getCurrentTimeZone, getFieldErrors, getFormErrors, initializeHttpClient, mergePurgeTargets, multiObjectStore, normalizeToTimestamp, noteStore, purgeCrmCombined, purgeCrmDetailAndListAfterCrmWrite, purgeCrmListCache, purgeCrmListCacheAfterCrmWrite, purgeCrmObjectDataCache, purgeCrmRecordCache, purgeEngagementCaches, purgeEngagementCachesAfterCrmWrite, resolveCrmListPurgeQuery, routeParam, store, syncStore, tableStore2 as tableStore, toCachePurgeListQuery, uploaderStore, url };
3932
+ //# sourceMappingURL=chunk-XQTQ4YHO.js.map
3933
+ //# sourceMappingURL=chunk-XQTQ4YHO.js.map