woodsportal-client-sdk 4.0.4-dev.9 → 4.0.7-dev.1

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.
Files changed (65) hide show
  1. package/dist/adapters/angular/index.d.ts +1 -0
  2. package/dist/adapters/angular/index.js +6 -4
  3. package/dist/adapters/angular/index.js.map +1 -1
  4. package/dist/adapters/react/index.d.ts +1 -0
  5. package/dist/adapters/react/index.js +6 -4
  6. package/dist/adapters/react/index.js.map +1 -1
  7. package/dist/adapters/vue/index.d.ts +1 -0
  8. package/dist/adapters/vue/index.js +6 -4
  9. package/dist/adapters/vue/index.js.map +1 -1
  10. package/dist/auth-error-codes-D7CXVBEN.js +3 -0
  11. package/dist/auth-error-codes-D7CXVBEN.js.map +1 -0
  12. package/dist/auth-interceptor-policy-LU2L5NJM.js +5 -0
  13. package/dist/auth-interceptor-policy-LU2L5NJM.js.map +1 -0
  14. package/dist/auth-utils-Z5P6SMLJ.js +5 -0
  15. package/dist/{auth-utils-MNMC2QGX.js.map → auth-utils-Z5P6SMLJ.js.map} +1 -1
  16. package/dist/chunk-55MIERLJ.js +3 -0
  17. package/dist/chunk-55MIERLJ.js.map +1 -0
  18. package/dist/chunk-6YOL5LPB.js +163 -0
  19. package/dist/chunk-6YOL5LPB.js.map +1 -0
  20. package/dist/chunk-B2OVKOJU.js +633 -0
  21. package/dist/chunk-B2OVKOJU.js.map +1 -0
  22. package/dist/chunk-BKT4MFQM.js +161 -0
  23. package/dist/chunk-BKT4MFQM.js.map +1 -0
  24. package/dist/{chunk-7Q6HRCUA.js → chunk-BURJ2NUL.js} +3 -3
  25. package/dist/{chunk-7Q6HRCUA.js.map → chunk-BURJ2NUL.js.map} +1 -1
  26. package/dist/chunk-COHBSTHF.js +82 -0
  27. package/dist/chunk-COHBSTHF.js.map +1 -0
  28. package/dist/{chunk-2TG7X2ML.js → chunk-FJAOCLB4.js} +12 -11
  29. package/dist/chunk-FJAOCLB4.js.map +1 -0
  30. package/dist/chunk-GUYIJ4ZE.js +165 -0
  31. package/dist/chunk-GUYIJ4ZE.js.map +1 -0
  32. package/dist/{chunk-VCYJAVD3.js → chunk-HAXXPW65.js} +167 -13
  33. package/dist/chunk-HAXXPW65.js.map +1 -0
  34. package/dist/{chunk-IBKBTIT6.js → chunk-OFPD644E.js} +6 -6
  35. package/dist/{chunk-IBKBTIT6.js.map → chunk-OFPD644E.js.map} +1 -1
  36. package/dist/{chunk-ZEJGWZK3.js → chunk-PFOSN7EB.js} +1242 -1269
  37. package/dist/chunk-PFOSN7EB.js.map +1 -0
  38. package/dist/{chunk-4AMFPSO2.js → chunk-WNE4LSVH.js} +465 -258
  39. package/dist/chunk-WNE4LSVH.js.map +1 -0
  40. package/dist/chunk-YNOZWRK3.js +306 -0
  41. package/dist/chunk-YNOZWRK3.js.map +1 -0
  42. package/dist/cross-tab-session-TUFJ6KU7.js +9 -0
  43. package/dist/cross-tab-session-TUFJ6KU7.js.map +1 -0
  44. package/dist/entries/auth.d.ts +17 -3
  45. package/dist/entries/auth.js +9 -4
  46. package/dist/entries/auth.js.map +1 -1
  47. package/dist/entries/crm.d.ts +1 -0
  48. package/dist/entries/crm.js +10 -6
  49. package/dist/entries/crm.js.map +1 -1
  50. package/dist/{http-errors-DqdtoJ1y.d.ts → http-errors-Bwhj6cfB.d.ts} +192 -9
  51. package/dist/index.d.ts +141 -3
  52. package/dist/index.js +16 -9
  53. package/dist/index.js.map +1 -1
  54. package/dist/refresh-lock-JQVP4YOS.js +72 -0
  55. package/dist/refresh-lock-JQVP4YOS.js.map +1 -0
  56. package/dist/storage-migration-BY2QL6YD.js +4 -0
  57. package/dist/storage-migration-BY2QL6YD.js.map +1 -0
  58. package/package.json +11 -9
  59. package/dist/auth-utils-MNMC2QGX.js +0 -3
  60. package/dist/chunk-2TG7X2ML.js.map +0 -1
  61. package/dist/chunk-4AMFPSO2.js.map +0 -1
  62. package/dist/chunk-QPSCMK4W.js +0 -237
  63. package/dist/chunk-QPSCMK4W.js.map +0 -1
  64. package/dist/chunk-VCYJAVD3.js.map +0 -1
  65. package/dist/chunk-ZEJGWZK3.js.map +0 -1
@@ -1,161 +1,8 @@
1
- import { getProfile, setProfileDetails, getCookie } from './chunk-QPSCMK4W.js';
2
- import axios from 'axios';
1
+ import { getProfile, logger, setProfileDetails } from './chunk-B2OVKOJU.js';
2
+ import { getStorageKeys, getCookie } from './chunk-YNOZWRK3.js';
3
3
  import pako from 'pako';
4
4
  import { Base64 } from 'js-base64';
5
5
 
6
- // src/main/core/utils/error-log-sanitize.ts
7
- var SENSITIVE_FIELD_NAMES = /* @__PURE__ */ new Set(["token", "refreshtoken", "accesstoken", "password", "secret", "authorization", "otp", "code"]);
8
- function isSensitiveField(name) {
9
- const normalized = name.toLowerCase();
10
- return SENSITIVE_FIELD_NAMES.has(normalized) || normalized.includes("password");
11
- }
12
- function redactValue(value) {
13
- if (value == null || typeof value !== "object") {
14
- return value;
15
- }
16
- if (Array.isArray(value)) {
17
- return value.map(redactValue);
18
- }
19
- const input = value;
20
- const output = {};
21
- for (const [key, nested] of Object.entries(input)) {
22
- output[key] = isSensitiveField(key) ? "[redacted]" : redactValue(nested);
23
- }
24
- return output;
25
- }
26
- function sanitizeAxiosErrorData(data) {
27
- if (data == null || typeof data !== "object") {
28
- return data;
29
- }
30
- const payload = data;
31
- const safeFields = ["errorCode", "message", "errorMessage", "detailedMessage", "correlationId", "category", "statusCode"];
32
- const summary = {};
33
- for (const field of safeFields) {
34
- if (field in payload) {
35
- summary[field] = payload[field];
36
- }
37
- }
38
- if (Object.keys(summary).length > 0) {
39
- return summary;
40
- }
41
- return redactValue(payload);
42
- }
43
- function redactLogMeta(meta) {
44
- if (meta == null) {
45
- return meta;
46
- }
47
- return redactValue(meta);
48
- }
49
-
50
- // src/main/core/logging/logger.ts
51
- var LEVEL_RANK = {
52
- debug: 0,
53
- info: 1,
54
- warn: 2,
55
- error: 3,
56
- silent: 4
57
- };
58
- var DEFAULT_CONFIG = {
59
- level: "info",
60
- namespace: "woodsportal-sdk",
61
- enabled: true,
62
- httpTracing: true
63
- };
64
- var runtimeConfig = { ...DEFAULT_CONFIG };
65
- var customSinks;
66
- function shouldEmit(level) {
67
- if (!runtimeConfig.enabled || runtimeConfig.level === "silent") {
68
- return false;
69
- }
70
- return LEVEL_RANK[level] >= LEVEL_RANK[runtimeConfig.level];
71
- }
72
- function formatPrefix(context) {
73
- return `[${runtimeConfig.namespace}] ${context}`;
74
- }
75
- function defaultDebug(context, message, meta) {
76
- if (meta != null) {
77
- console.debug(formatPrefix(context), message, meta);
78
- return;
79
- }
80
- console.debug(formatPrefix(context), message);
81
- }
82
- function defaultInfo(context, message, meta) {
83
- if (meta != null) {
84
- console.info(formatPrefix(context), message, meta);
85
- return;
86
- }
87
- console.info(formatPrefix(context), message);
88
- }
89
- function defaultWarn(context, message, meta) {
90
- if (meta != null) {
91
- console.warn(formatPrefix(context), message, meta);
92
- return;
93
- }
94
- console.warn(formatPrefix(context), message);
95
- }
96
- function defaultError(context, error, meta) {
97
- if (axios.isAxiosError(error)) {
98
- const payload = {
99
- message: error.message,
100
- status: error.response?.status,
101
- statusText: error.response?.statusText,
102
- data: sanitizeAxiosErrorData(error.response?.data),
103
- url: error.config?.url,
104
- method: error.config?.method,
105
- ...redactLogMeta(meta)
106
- };
107
- console.error(formatPrefix(context), payload);
108
- return;
109
- }
110
- if (error instanceof Error) {
111
- if (meta != null) {
112
- console.error(formatPrefix(context), error.message, error, redactLogMeta(meta));
113
- return;
114
- }
115
- console.error(formatPrefix(context), error.message, error);
116
- return;
117
- }
118
- if (meta != null) {
119
- console.error(formatPrefix(context), error, redactLogMeta(meta));
120
- return;
121
- }
122
- console.error(formatPrefix(context), error);
123
- }
124
- function configureLogger(config = {}) {
125
- runtimeConfig = {
126
- level: config.level ?? DEFAULT_CONFIG.level,
127
- namespace: config.namespace ?? DEFAULT_CONFIG.namespace,
128
- enabled: config.enabled ?? DEFAULT_CONFIG.enabled,
129
- httpTracing: config.httpTracing ?? DEFAULT_CONFIG.httpTracing
130
- };
131
- customSinks = config.sinks;
132
- }
133
- function isHttpTracingEnabled() {
134
- return runtimeConfig.enabled && runtimeConfig.httpTracing && shouldEmit("debug");
135
- }
136
- var logger = {
137
- debug(context, message, meta) {
138
- if (!shouldEmit("debug")) return;
139
- const sink = customSinks?.debug ?? defaultDebug;
140
- sink(context, message, redactLogMeta(meta));
141
- },
142
- info(context, message, meta) {
143
- if (!shouldEmit("info")) return;
144
- const sink = customSinks?.info ?? defaultInfo;
145
- sink(context, message, redactLogMeta(meta));
146
- },
147
- warn(context, message, meta) {
148
- if (!shouldEmit("warn")) return;
149
- const sink = customSinks?.warn ?? defaultWarn;
150
- sink(context, message, redactLogMeta(meta));
151
- },
152
- error(context, error, meta) {
153
- if (!shouldEmit("error")) return;
154
- const sink = customSinks?.error ?? defaultError;
155
- sink(context, error, redactLogMeta(meta));
156
- }
157
- };
158
-
159
6
  // src/main/state/crm/store.ts
160
7
  function createStore(initialState) {
161
8
  let state = initialState;
@@ -202,1188 +49,1312 @@ var tableUiStore = createStore({
202
49
  tableDefPermissions: {}
203
50
  });
204
51
 
205
- // src/main/state/crm/use-form.ts
206
- var formStore = createStore({
207
- form: null
208
- });
209
- var actions = {
210
- setFormData(response) {
211
- formStore.setState({
212
- form: response
213
- });
214
- },
215
- clearFormData() {
216
- formStore.setState({
217
- form: null
218
- });
219
- }
52
+ // src/main/core/utils/getCookieData.ts
53
+ var getAuthSubscriptionType = () => {
54
+ const keys = getStorageKeys();
55
+ return getCookie(keys.subscriptionType) ?? getCookie("subscriptionType") ?? getCookie("woodsportal_subscription");
220
56
  };
57
+ function convertToBase64(obj) {
58
+ try {
59
+ if (!obj) return "";
60
+ const json = JSON.stringify(obj);
61
+ const compressed = pako.deflate(json);
62
+ const base64 = Base64.fromUint8Array(compressed, true);
63
+ return base64;
64
+ } catch (error) {
65
+ logger.error("compress", error, { operation: "encode" });
66
+ return "";
67
+ }
68
+ }
69
+ function decodeToBase64(encoded) {
70
+ try {
71
+ if (!encoded) return null;
72
+ const uint8Array = Base64.toUint8Array(encoded);
73
+ const decompressed = pako.inflate(uint8Array, { to: "string" });
74
+ return JSON.parse(decompressed);
75
+ } catch (error) {
76
+ logger.error("compress", error, { operation: "decode" });
77
+ return null;
78
+ }
79
+ }
221
80
 
222
- // src/main/state/crm/use-table.ts
223
- var tableStore = createStore({
224
- queryParams: null,
225
- multiObjectsQueryParams: {},
226
- objectsData: null,
227
- tableData: [],
228
- tablePrependData: [],
229
- hubspotObjectTypeId: "",
230
- selectedPipeline: "",
231
- viewType: ""
232
- });
233
- var actions2 = {
234
- /** Called from Client.object.list — feeds purgeCrmListCacheAfterCrmWrite / purgeCrmDetailAndListAfterCrmWrite. */
235
- setObjectsQueryParams(params) {
236
- tableStore.setState({
237
- queryParams: params
238
- });
239
- },
240
- /** Called from Client.object.sideBarList — feeds post-write list purge for sidebarTable writes. */
241
- setMultiObjectsQueryParams(hubspotObjectTypeId, params) {
242
- if (!hubspotObjectTypeId) {
243
- return;
244
- }
245
- const state = tableStore.getState();
246
- tableStore.setState({
247
- multiObjectsQueryParams: {
248
- ...state.multiObjectsQueryParams,
249
- [String(hubspotObjectTypeId)]: params
250
- }
251
- });
252
- },
253
- async setObjectsData(response, context) {
254
- const state = tableStore.getState();
255
- if (response?.info?.viewType == "LIST") {
256
- tableStore.setState({
257
- objectsData: response
258
- });
81
+ // src/main/features/navigation/url-utils.ts
82
+ function mapKeysDeep(obj, keyMap2) {
83
+ if (Array.isArray(obj)) {
84
+ return obj.map((item) => mapKeysDeep(item, keyMap2));
85
+ } else if (obj !== null && typeof obj === "object") {
86
+ return Object.entries(obj).reduce(
87
+ (acc, [key, value]) => {
88
+ const mappedKey = keyMap2[key] || key;
89
+ acc[mappedKey] = mapKeysDeep(value, keyMap2);
90
+ return acc;
91
+ },
92
+ {}
93
+ );
94
+ }
95
+ return obj;
96
+ }
97
+ function isMessingParent(breadcrumbs) {
98
+ const lastItem = breadcrumbs[breadcrumbs.length - 1];
99
+ const lastItem2 = breadcrumbs[breadcrumbs.length - 2];
100
+ const lastItem3 = breadcrumbs[breadcrumbs.length - 3];
101
+ return lastItem?.o_r_id && !lastItem2?.o_r_id && lastItem2?.o_t_id && lastItem3?.o_r_id ? true : false;
102
+ }
103
+ function isMessingParentLastItem(breadcrumbs) {
104
+ const lastItem = breadcrumbs[breadcrumbs.length - 1];
105
+ const lastItem2 = breadcrumbs[breadcrumbs.length - 2];
106
+ return !lastItem?.o_t_id && lastItem2?.o_r_id && lastItem2?.o_t_id ? false : true;
107
+ }
108
+ function breadcrumbStage(breadcrumbItems) {
109
+ let breadcrumbType = "child";
110
+ if (breadcrumbItems.length === 1) {
111
+ breadcrumbType = "root";
112
+ } else if (breadcrumbItems.length === 2) {
113
+ breadcrumbType = "root_details";
114
+ }
115
+ return breadcrumbType;
116
+ }
117
+ var generateUrl = (props, breadcrumbs) => {
118
+ const newBase64 = convertToBase64(breadcrumbs);
119
+ let url = "";
120
+ if (props?.objectTypeId && props?.recordId) {
121
+ url = `/${props?.recordId}/${props?.objectTypeId}/${props?.recordId}?b=${newBase64}`;
122
+ } else {
123
+ url = `/association/${props?.objectTypeId}?b=${newBase64}`;
124
+ }
125
+ return url;
126
+ };
127
+ function getTotalParentLength(data) {
128
+ return data.filter((item) => (item.pt || item.o_t_id) && !item.o_r_id).length;
129
+ }
130
+ var generatePath = (breadcrumbs, breadcrumb, index) => {
131
+ const bc = convertToBase64(breadcrumbs.slice(0, index + 1));
132
+ if (index === 0) {
133
+ const pathBase = breadcrumb?.pt || `/${breadcrumb?.o_t_id}`;
134
+ const normalizedPath = pathBase.startsWith("/") ? pathBase : `/${pathBase}`;
135
+ return {
136
+ name: breadcrumb?.n,
137
+ path: `${normalizedPath}?b=${bc}`
138
+ };
139
+ } else if (index === 1) {
140
+ if (breadcrumb?.isHome) {
141
+ return {
142
+ name: breadcrumb?.n,
143
+ path: `/association/${breadcrumb?.o_t_id}?b=${bc}`
144
+ };
259
145
  }
260
- if (response?.info?.viewType == "BOARD") {
261
- const storeStageId = tableUiStore.getState().stageId;
262
- const stageId = storeStageId !== void 0 && storeStageId !== null && storeStageId !== "" ? storeStageId : context?.stageId;
263
- if (stageId) {
264
- const existingResults = state.objectsData?.data?.results;
265
- if (!Array.isArray(existingResults)) {
266
- tableStore.setState({
267
- objectsData: response
268
- });
269
- return;
270
- }
271
- const boardData = { ...state.objectsData };
272
- const updatedBoardData = await {
273
- ...boardData,
274
- data: {
275
- ...boardData.data,
276
- results: boardData.data.results.map(
277
- (item) => String(item.id) === String(stageId) ? {
278
- ...item,
279
- data: {
280
- ...item.data,
281
- results: {
282
- ...item.data.results,
283
- rows: [
284
- ...item?.data?.results?.rows ?? [],
285
- // keep existing rows
286
- ...response?.data?.results?.rows ?? []
287
- // prepend new rows
288
- ]
289
- }
290
- }
291
- } : item
292
- )
293
- }
294
- };
295
- tableStore.setState({
296
- objectsData: updatedBoardData
297
- });
298
- } else {
299
- tableStore.setState({
300
- objectsData: response
301
- });
302
- }
146
+ return {
147
+ name: breadcrumb?.n,
148
+ path: `/${breadcrumb?.o_r_id}/${breadcrumb?.o_t_id}/${breadcrumb?.o_r_id}?b=${bc}`
149
+ };
150
+ } else {
151
+ if (breadcrumb?.o_t_id && breadcrumb?.o_r_id && !breadcrumb?.isHome) {
152
+ return {
153
+ name: breadcrumb?.n,
154
+ path: `/${breadcrumb?.o_r_id}/${breadcrumb?.o_t_id}/${breadcrumb?.o_r_id}?b=${bc}`
155
+ };
156
+ } else {
157
+ return {
158
+ name: breadcrumb?.n,
159
+ path: `/association/${breadcrumb?.o_t_id}?b=${bc}`
160
+ };
303
161
  }
304
- },
305
- setTableData(response, payload) {
306
- const state = tableStore.getState();
307
- const viewType = response?.info?.viewType;
308
- let newTablePrependData;
309
- if (viewType === "BOARD") {
310
- const stages = response?.data?.results ?? [];
311
- newTablePrependData = state.tablePrependData.map((prependStage) => {
312
- const matchingStage = stages.find((stage) => String(stage.id) === String(prependStage.id));
313
- const rows = matchingStage?.data?.results?.rows ?? [];
314
- const rowIds = new Set(
315
- rows.map((row) => row.id ?? row.hs_object_id).filter((id) => id != null && id !== "").map((id) => String(id))
316
- );
317
- const filteredRows = (prependStage?.data?.results?.rows ?? []).filter((item) => {
318
- const itemId = item.id ?? item.hs_object_id;
319
- if (itemId == null || itemId === "") return true;
320
- return !rowIds.has(String(itemId));
321
- });
322
- return {
323
- ...prependStage,
324
- data: {
325
- ...prependStage.data,
326
- results: {
327
- ...prependStage.data?.results,
328
- rows: filteredRows
329
- }
330
- }
331
- };
332
- });
333
- } else {
334
- const rows = response?.data?.results?.rows ?? [];
335
- const rowIds = new Set(
336
- rows.map((row) => row.id ?? row.hs_object_id).filter((id) => id != null && id !== "").map((id) => String(id))
337
- );
338
- newTablePrependData = state.tablePrependData.filter((item) => {
339
- const itemId = item.id ?? item.hs_object_id;
340
- if (itemId == null || itemId === "") return true;
341
- return !rowIds.has(String(itemId));
342
- });
343
- }
344
- const hubspotObjectTypeId = payload?.hubspotObjectTypeId;
345
- const selectedPipeline = payload?.selectedPipeline;
346
- if (response?.data?.total < 1 || payload?.componentName) {
347
- newTablePrependData = [];
348
- }
349
- if (state.viewType && state.viewType != viewType) {
350
- newTablePrependData = [];
351
- }
352
- if (state.hubspotObjectTypeId && state.hubspotObjectTypeId != hubspotObjectTypeId) {
353
- newTablePrependData = [];
354
- }
355
- if (state.selectedPipeline && state.selectedPipeline != selectedPipeline) {
356
- newTablePrependData = [];
357
- }
358
- if (payload.isFristTimeLoadData) {
359
- newTablePrependData = [];
360
- }
361
- tableStore.setState({
362
- tableData: response,
363
- tablePrependData: newTablePrependData || [],
364
- hubspotObjectTypeId,
365
- viewType
366
- });
367
- },
368
- modifiedObjectsData(results) {
369
- const state = tableStore.getState();
370
- const tablePrependData = state.tablePrependData;
371
- const modifiedData = results.map((result) => {
372
- const matchedPrepend = tablePrependData.find((item) => String(item?.id) === String(result?.id));
373
- if (!matchedPrepend) {
374
- return result;
375
- }
376
- const prependRows = matchedPrepend?.data?.results?.rows ?? [];
377
- const prependCards = prependRows.map((row) => ({
378
- id: row.hs_object_id,
379
- ...row
380
- }));
381
- return {
382
- ...result,
383
- // prepend in results.rows
384
- data: {
385
- ...result.data,
386
- results: {
387
- ...result.data.results,
388
- rows: [...prependRows, ...result?.data?.results?.rows ?? []]
389
- }
390
- },
391
- // prepend in cards
392
- cards: [...prependCards, ...result?.cards ?? []]
393
- };
394
- });
395
- tableStore.setState({
396
- objectsData: modifiedData
397
- });
398
- },
399
- clearTablePrependData() {
400
- tableStore.setState({
401
- tablePrependData: []
402
- });
403
- },
404
- async setTablePrependData(response, props) {
405
- const state = tableStore.getState();
406
- const formState = formStore.getState();
407
- let rows = [];
408
- if (state.tableData?.info?.viewType == "BOARD") {
409
- if (response === "loading") {
410
- const responseData = state.tableData?.data?.results ?? [];
411
- const pipelineStage = props?.payload?.propertyPayload?.hs_pipeline_stage || props?.payload?.propertyPayload?.dealstage || formState?.form?.data?.pipelineDefaults?.defaultStage?.id;
412
- rows = responseData.map(({ id, data }) => {
413
- const matchedPrepend = state.tablePrependData.find((item) => String(item.id) === String(id));
414
- const prependRows = matchedPrepend?.data?.results?.rows ?? [];
415
- const newRow = String(id) === String(pipelineStage) ? [
416
- (data?.results?.columns ?? []).reduce((obj, column) => {
417
- obj[column.key] = "loading";
418
- return obj;
419
- }, {})
420
- ] : [];
421
- return {
422
- id,
423
- data: {
424
- results: {
425
- columns: data?.results?.columns ?? [],
426
- // prepend loading row + prepend rows
427
- rows: [...newRow, ...prependRows]
428
- }
429
- }
430
- };
431
- });
432
- } else {
433
- const data = response?.data;
434
- const hs_pipeline_stage = data?.hs_pipeline_stage?.value?.value || data?.dealstage?.value?.value;
435
- if (!data) {
436
- tableStore.setState({
437
- tablePrependData: []
438
- });
439
- }
440
- rows = state?.tablePrependData.map((row) => {
441
- const matchedPrepend = state.tablePrependData.find((item) => String(item.id) === String(row.id));
442
- const prependRows = matchedPrepend?.data?.results?.rows ?? [];
443
- if (String(row.id) === String(hs_pipeline_stage)) {
444
- const updatedRow = (row?.data?.results?.columns ?? []).reduce((obj, column) => {
445
- const key = column.key;
446
- obj[key] = data?.[key]?.value ?? data?.[key] ?? "";
447
- return obj;
448
- }, {});
449
- prependRows[0] = updatedRow;
450
- return {
451
- ...row,
452
- data: {
453
- ...row.data,
454
- results: {
455
- ...row.data.results,
456
- rows: prependRows
457
- }
458
- }
459
- };
460
- }
461
- return row;
462
- });
463
- }
464
- } else if (state.tableData?.info?.viewType == "LIST") {
465
- if (response === "loading") {
466
- const row = await state.tableData?.data?.results?.columns.reduce((acc, item) => {
467
- if (!item.hidden) {
468
- acc[item.key] = "loading";
469
- }
470
- return acc;
471
- }, {});
472
- rows = [row, ...state.tablePrependData];
473
- } else if (response?.data) {
474
- const data = response?.data;
475
- if (!data) {
476
- tableStore.setState({
477
- tablePrependData: []
478
- });
479
- }
480
- const row = await Object.fromEntries(Object.entries(data).map(([key, value]) => [key, value?.value ?? value]));
481
- rows = [...state.tablePrependData];
482
- if (rows.length > 0) {
483
- rows[0] = row;
484
- } else {
485
- rows.push(row);
486
- }
487
- }
488
- }
489
- tableStore.setState({
490
- tablePrependData: rows
491
- });
492
162
  }
493
163
  };
494
164
 
495
- // src/main/state/crm/use-uploader.ts
496
- var uploaderStore = createStore({
497
- attachments: []
498
- });
499
- function toAttachmentSummary(attachment) {
500
- return {
501
- createdAt: attachment.createdAt,
502
- id: attachment.id,
503
- name: attachment.name,
504
- size: attachment.size,
505
- type: attachment.type,
506
- updatedAt: attachment.updatedAt
507
- };
508
- }
509
- function resolveAttachmentsFromIds(attachmentIds, storedAttachments) {
510
- const raw = typeof attachmentIds === "object" && attachmentIds !== null && "value" in attachmentIds ? attachmentIds.value : attachmentIds;
511
- const ids = String(raw ?? "").split(";").map((id) => id.trim()).filter(Boolean);
512
- return ids.map((id) => storedAttachments.find((a) => String(a.id) === id)).filter((a) => a != null).map(toAttachmentSummary);
513
- }
514
- var actions3 = {
515
- setAttachment(response) {
516
- const data = response?.data;
517
- if (!data?.id) return;
518
- const state = uploaderStore.getState();
519
- const id = String(data.id);
520
- const existing = state.attachments;
521
- const index = existing.findIndex((item) => String(item.id) === id);
522
- const attachments = index >= 0 ? existing.map((item, i) => i === index ? data : item) : [...existing, data];
523
- uploaderStore.setState({ attachments });
524
- },
525
- clearAttachments() {
526
- uploaderStore.setState({ attachments: [] });
527
- }
528
- };
529
-
530
- // src/main/state/crm/use-note.ts
531
- var noteStore = createStore({
532
- notes: [],
533
- prependNotes: [],
534
- id: "",
535
- queryParams: null
536
- });
537
- var actions4 = {
538
- /** Called from Client.note.list — feeds purgeEngagementCaches (view: notes). */
539
- setListQueryParams(params) {
540
- noteStore.setState({
541
- queryParams: params
542
- });
543
- },
544
- setNotes(response, payload) {
545
- const state = noteStore.getState();
546
- const rows = response?.data?.results?.rows ?? [];
547
- const rowIds = new Set(
548
- rows.map((row) => row.id ?? row.hs_object_id).filter((id2) => id2 != null && id2 !== "").map((id2) => String(id2))
549
- );
550
- let newPrependNotes = state.prependNotes.filter((item) => {
551
- const itemId = item.id ?? item.hs_object_id;
552
- if (itemId == null || itemId === "") return true;
553
- return !rowIds.has(String(itemId));
554
- });
555
- const id = payload?.params?.id;
556
- if (state.id && state.id != id) {
557
- newPrependNotes = [];
558
- }
559
- noteStore.setState({
560
- notes: response,
561
- prependNotes: newPrependNotes,
562
- id
563
- });
564
- },
565
- async setPrependNote(response) {
566
- const state = noteStore.getState();
567
- let rows = [];
568
- if (response === "loading") {
569
- const row = await state.notes?.data?.results?.columns.reduce((acc, item) => {
570
- if (!item.hidden) {
571
- acc[item.key] = "loading";
572
- }
573
- return acc;
574
- }, {});
575
- rows = [row, ...state.prependNotes];
576
- } else if (response?.data) {
577
- const data = response?.data;
578
- if (!data) {
579
- noteStore.setState({
580
- prependNotes: []
581
- });
582
- }
583
- const storedAttachments = uploaderStore.getState().attachments;
584
- const row = Object.fromEntries(
585
- Object.entries(data).map(([key, value]) => {
586
- if (key === "hs_attachment_ids") {
587
- return [key, resolveAttachmentsFromIds(value, storedAttachments)];
588
- }
589
- return [key, value?.value ?? value];
590
- })
591
- );
592
- rows = [...state.prependNotes];
593
- if (rows.length > 0) {
594
- rows[0] = row;
595
- } else {
596
- rows.push(row);
597
- }
598
- }
599
- noteStore.setState({
600
- prependNotes: rows
601
- });
602
- },
603
- clearPrependNotes() {
604
- noteStore.setState({
605
- prependNotes: []
606
- });
607
- actions3.clearAttachments();
608
- },
609
- async updatePrependNote(response) {
610
- const responseData = { ...response };
611
- const state = noteStore.getState();
612
- const prependNotes = state.prependNotes || [];
613
- const note = response.data || null;
614
- const storedAttachments = uploaderStore.getState().attachments;
615
- const notes = prependNotes.map(
616
- (item) => item?.hs_object_id === note?.hs_object_id?.value ? {
617
- ...item,
618
- ...Object.fromEntries(
619
- Object.entries(note).map(([key, value]) => {
620
- if (key === "hs_attachment_ids") {
621
- return [key, resolveAttachmentsFromIds(value, storedAttachments)];
622
- }
623
- return [key, value?.value ?? value];
624
- })
625
- )
626
- } : item
627
- );
628
- noteStore.setState({
629
- prependNotes: notes
630
- });
631
- if (responseData?.data?.hs_attachment_ids != null) {
632
- const noteObjectId = note?.hs_object_id?.value;
633
- const rows = state.notes?.data?.results?.rows ?? [];
634
- const matchingRow = rows.find((row) => String(row.hs_object_id) === String(noteObjectId));
635
- const originalPrependItem = notes.find((item) => String(item?.hs_object_id) === String(noteObjectId));
636
- const existingAttachments = matchingRow?.hs_attachment_ids ?? originalPrependItem?.hs_attachment_ids ?? [];
637
- const newAttachments = resolveAttachmentsFromIds(responseData.data.hs_attachment_ids, storedAttachments);
638
- const mergedAttachments = [
639
- ...existingAttachments,
640
- ...newAttachments.filter((attachment) => !existingAttachments.some((existing) => String(existing.id) === String(attachment.id)))
641
- ];
642
- const stateUpdates = {};
643
- if (matchingRow && state.notes?.data?.results) {
644
- stateUpdates.notes = {
645
- ...state.notes,
646
- data: {
647
- ...state.notes.data,
648
- results: {
649
- ...state.notes.data.results,
650
- rows: rows.map(
651
- (row) => String(row.hs_object_id) === String(noteObjectId) ? { ...row, hs_attachment_ids: mergedAttachments } : row
652
- )
653
- }
654
- }
655
- };
656
- }
657
- if (originalPrependItem) {
658
- stateUpdates.prependNotes = notes.map(
659
- (item) => String(item?.hs_object_id) === String(noteObjectId) ? { ...item, hs_attachment_ids: mergedAttachments } : item
660
- );
661
- }
662
- if (Object.keys(stateUpdates).length > 0) {
663
- noteStore.setState(stateUpdates);
664
- }
665
- responseData.data.hs_attachment_ids = mergedAttachments;
666
- }
667
- return responseData;
668
- }
165
+ // src/main/features/navigation/key-map.ts
166
+ var keyMap = {
167
+ dp: "defPermissions",
168
+ n: "name",
169
+ sort: "sort",
170
+ o_t_id: "objectTypeId",
171
+ s: "search",
172
+ fPn: "filterPropertyName",
173
+ fO: "filterOperator",
174
+ fV: "filterValue",
175
+ c: "cache",
176
+ isPC: "isPrimaryCompany",
177
+ v: "view",
178
+ l: "limit",
179
+ pt: "path",
180
+ p: "page",
181
+ a: "after",
182
+ aPip: "activePipeline",
183
+ aT: "activeTab",
184
+ cT: "create",
185
+ dP: "display",
186
+ dL: "display_label",
187
+ pId: "pipeline_id"
669
188
  };
670
189
 
671
- // src/main/state/crm/use-email.ts
672
- var emailStore = createStore({
673
- emails: [],
674
- prependEmails: [],
675
- id: "",
676
- queryParams: null
677
- });
678
- var actions5 = {
679
- /** Called from Client.email.list feeds purgeEngagementCaches (view: emails). */
680
- setListQueryParams(params) {
681
- emailStore.setState({
682
- queryParams: params
683
- });
684
- },
685
- setEmails(response, payload) {
686
- const state = emailStore.getState();
687
- const rows = response?.data?.results?.rows ?? [];
688
- const rowIds = new Set(
689
- rows.map((row) => row.id ?? row.hs_object_id).filter((id2) => id2 != null && id2 !== "").map((id2) => String(id2))
690
- );
691
- let newPrependEmails = state.prependEmails.filter((item) => {
692
- const itemId = item.id ?? item.hs_object_id;
693
- if (itemId == null || itemId === "") return true;
694
- return !rowIds.has(String(itemId));
695
- });
696
- const id = payload?.params?.id;
697
- if (state.id && state.id != id) {
698
- newPrependEmails = [];
699
- }
700
- emailStore.setState({
701
- emails: response,
702
- prependEmails: newPrependEmails,
703
- id
704
- });
705
- },
706
- async setPrependEmail(response) {
707
- const state = emailStore.getState();
708
- let rows = [];
709
- if (response === "loading") {
710
- const row = await state.emails?.data?.results?.columns.reduce((acc, item) => {
711
- if (!item.hidden) {
712
- acc[item.key] = "loading";
713
- }
714
- return acc;
715
- }, {});
716
- rows = [row, ...state.prependEmails];
717
- } else if (response?.data) {
718
- const data = response?.data;
719
- if (!data) {
720
- emailStore.setState({
721
- prependEmails: []
722
- });
723
- }
724
- const storedAttachments = uploaderStore.getState().attachments;
725
- const row = Object.fromEntries(
726
- Object.entries(data).map(([key, value]) => {
727
- if (key === "hs_attachment_ids") {
728
- return [key, resolveAttachmentsFromIds(value, storedAttachments)];
729
- }
730
- return [key, value?.value ?? value];
731
- })
732
- );
733
- rows = [...state.prependEmails];
734
- if (rows.length > 0) {
735
- rows[0] = row;
736
- } else {
737
- rows.push(row);
738
- }
739
- }
740
- emailStore.setState({
741
- prependEmails: rows
742
- });
743
- },
744
- clearPrependEmails() {
745
- emailStore.setState({
746
- prependEmails: []
747
- });
748
- actions3.clearAttachments();
749
- },
750
- async updatePrependEmail(response) {
751
- const responseData = { ...response };
752
- const state = emailStore.getState();
753
- const prependEmails = state.prependEmails || [];
754
- const email = response.data || null;
755
- const storedAttachments = uploaderStore.getState().attachments;
756
- const emails = prependEmails.map(
757
- (item) => item?.hs_object_id === email?.hs_object_id?.value ? {
758
- ...item,
759
- ...Object.fromEntries(
760
- Object.entries(email).map(([key, value]) => {
761
- if (key === "hs_attachment_ids") {
762
- return [key, resolveAttachmentsFromIds(value, storedAttachments)];
763
- }
764
- return [key, value?.value ?? value];
765
- })
766
- )
767
- } : item
768
- );
769
- emailStore.setState({
770
- prependEmails: emails
771
- });
772
- if (responseData?.data?.hs_attachment_ids != null) {
773
- const emailObjectId = email?.hs_object_id?.value;
774
- const rows = state.emails?.data?.results?.rows ?? [];
775
- const matchingRow = rows.find((row) => String(row.hs_object_id) === String(emailObjectId));
776
- const originalPrependItem = emails.find((item) => String(item?.hs_object_id) === String(emailObjectId));
777
- const existingAttachments = matchingRow?.hs_attachment_ids ?? originalPrependItem?.hs_attachment_ids ?? [];
778
- const newAttachments = resolveAttachmentsFromIds(responseData.data.hs_attachment_ids, storedAttachments);
779
- const mergedAttachments = [
780
- ...existingAttachments,
781
- ...newAttachments.filter((attachment) => !existingAttachments.some((existing) => String(existing.id) === String(attachment.id)))
782
- ];
783
- const stateUpdates = {};
784
- if (matchingRow && state.emails?.data?.results) {
785
- stateUpdates.emails = {
786
- ...state.emails,
787
- data: {
788
- ...state.emails.data,
789
- results: {
790
- ...state.emails.data.results,
791
- rows: rows.map(
792
- (row) => String(row.hs_object_id) === String(emailObjectId) ? { ...row, hs_attachment_ids: mergedAttachments } : row
793
- )
794
- }
795
- }
796
- };
190
+ // src/main/features/navigation/param.ts
191
+ var getRouteMenu = (path) => {
192
+ const apiRoutes = globalThis?.apiRoutes || [];
193
+ return apiRoutes.find((menu) => menu?.path === path);
194
+ };
195
+ var getRouteDetails = () => {
196
+ const search = getParam("b");
197
+ const breadcrumbs = decodeToBase64(search) || [];
198
+ const lastItem = breadcrumbs[breadcrumbs.length - 1];
199
+ const mapped = lastItem ? mapKeysDeep(lastItem, keyMap) : null;
200
+ return { routeDetails: mapped };
201
+ };
202
+ var getParamDetails = (props, isDetailsPage = false) => {
203
+ const search = getParam("b");
204
+ let breadcrumbs = decodeToBase64(search) || [];
205
+ if (breadcrumbs.length > 0 && breadcrumbs?.[0]?.isHome) {
206
+ breadcrumbs = breadcrumbs.slice(1);
207
+ }
208
+ let mediatorObjectTypeId = "";
209
+ let mediatorObjectRecordId = "";
210
+ let parentObjectTypeId = "";
211
+ let parentObjectRecordId = "";
212
+ const lastItem = breadcrumbs[breadcrumbs.length - 1];
213
+ const lastItem2 = breadcrumbs[breadcrumbs.length - 2];
214
+ const lastItem3 = breadcrumbs[breadcrumbs.length - 3];
215
+ if (isDetailsPage === true && lastItem && "prm" in lastItem) {
216
+ delete lastItem.prm;
217
+ }
218
+ if (breadcrumbs.length > 1) {
219
+ if (props?.type === "ticket" || props?.type === "association" || props?.type === "sidebarAssociation") {
220
+ mediatorObjectTypeId = breadcrumbs[1]?.o_t_id || "";
221
+ mediatorObjectRecordId = breadcrumbs[1]?.o_r_id || "";
222
+ if (lastItem?.o_t_id && lastItem?.o_r_id) {
223
+ parentObjectTypeId = lastItem?.o_t_id || "";
224
+ parentObjectRecordId = lastItem?.o_r_id || "";
225
+ } else if (lastItem2?.o_t_id && lastItem2?.o_r_id) {
226
+ parentObjectTypeId = lastItem2?.o_t_id || "";
227
+ parentObjectRecordId = lastItem2?.o_r_id || "";
797
228
  }
798
- if (originalPrependItem) {
799
- stateUpdates.prependEmails = emails.map(
800
- (item) => String(item?.hs_object_id) === String(emailObjectId) ? { ...item, hs_attachment_ids: mergedAttachments } : item
801
- );
229
+ } else {
230
+ if (breadcrumbs.length > 2) {
231
+ mediatorObjectTypeId = breadcrumbs[1]?.o_t_id || "";
232
+ mediatorObjectRecordId = breadcrumbs[1]?.o_r_id || "";
802
233
  }
803
- if (Object.keys(stateUpdates).length > 0) {
804
- emailStore.setState(stateUpdates);
234
+ if (!lastItem?.o_r_id && breadcrumbs.length > 2) {
235
+ parentObjectTypeId = lastItem2?.o_t_id || "";
236
+ parentObjectRecordId = lastItem2?.o_r_id || "";
237
+ }
238
+ if (lastItem?.o_r_id && breadcrumbs.length > 2) {
239
+ parentObjectTypeId = lastItem3?.o_t_id || "";
240
+ parentObjectRecordId = lastItem3?.o_r_id || "";
241
+ }
242
+ if (lastItem2?.o_t_id === "0-5" && !parentObjectTypeId && !parentObjectRecordId) {
243
+ parentObjectTypeId = lastItem2?.o_t_id || "";
244
+ parentObjectRecordId = lastItem2?.o_r_id || "";
805
245
  }
806
- responseData.data.hs_attachment_ids = mergedAttachments;
807
246
  }
808
- return responseData;
809
247
  }
248
+ const paramsObject = {};
249
+ if (breadcrumbs[0]?.prm?.isPC || breadcrumbs[1]?.prm?.isPC || lastItem?.prm?.isPC) {
250
+ paramsObject["isPrimaryCompany"] = true;
251
+ }
252
+ if (parentObjectTypeId && parentObjectRecordId) {
253
+ paramsObject["parentObjectTypeId"] = parentObjectTypeId;
254
+ paramsObject["parentObjectRecordId"] = parentObjectRecordId;
255
+ }
256
+ if (mediatorObjectTypeId && mediatorObjectRecordId) {
257
+ paramsObject["mediatorObjectTypeId"] = mediatorObjectTypeId;
258
+ paramsObject["mediatorObjectRecordId"] = mediatorObjectRecordId;
259
+ }
260
+ const mappedLastItemParam = Object.fromEntries(
261
+ Object.entries(lastItem?.prm || {}).map(([key, value]) => [
262
+ keyMap[key] || key,
263
+ // use mapped name if exists, else keep original
264
+ value
265
+ ])
266
+ );
267
+ let queryString = null;
268
+ if (props?.type === "association" || props?.type === "sidebarAssociation") {
269
+ queryString = new URLSearchParams({ ...paramsObject, ...{ cache: false } }).toString();
270
+ } else {
271
+ queryString = new URLSearchParams({ ...paramsObject, ...mappedLastItemParam }).toString();
272
+ }
273
+ const params = queryString ? `?${queryString}` : "";
274
+ const totalParentLength = getTotalParentLength(breadcrumbs);
275
+ let parentAccessLabel = false;
276
+ if (breadcrumbs[0]?.prm?.isPC && totalParentLength > 2 || // company object
277
+ !breadcrumbs[0]?.prm?.isPC && totalParentLength > 3 || // normal object
278
+ breadcrumbs[0]?.prm?.isPC && totalParentLength > 1 && props?.type === "ticket" || // company ticket
279
+ !breadcrumbs[0]?.prm?.isPC && totalParentLength > 2 && props?.type === "ticket") {
280
+ parentAccessLabel = true;
281
+ }
282
+ return {
283
+ breadcrumbs,
284
+ // paramsObject: Object.keys(mParamsObject).length === 0 ? null : mParamsObject,
285
+ paramsObject,
286
+ params,
287
+ parentAccessLabel
288
+ };
810
289
  };
811
290
 
812
- // src/main/state/crm/use-user.ts
813
- var userStore = createStore({
814
- profile: getProfile()
815
- });
816
- var actions6 = {
817
- setProfile(response) {
818
- const data = response?.data || null;
819
- userStore.setState({
820
- profile: data
821
- });
822
- setProfileDetails(data);
291
+ // src/main/core/utils/url.ts
292
+ var ticketHubspotObjectTypeId = () => {
293
+ const paramDetails = getParamDetails();
294
+ if (
295
+ // this hubspotObjectTypeId only for main contact ticket object type
296
+ paramDetails?.breadcrumbs?.length === 2 && paramDetails?.breadcrumbs[0]?.pt === "/0-5"
297
+ ) {
298
+ return "0-1";
299
+ }
300
+ if (
301
+ // this hubspotObjectTypeId only for main company ticket object type
302
+ paramDetails?.breadcrumbs?.length === 2 && paramDetails?.breadcrumbs[0]?.pt === "/0-5-c"
303
+ ) {
304
+ return "0-2";
823
305
  }
306
+ return "";
824
307
  };
825
308
 
826
- // src/main/core/utils/getCookieData.ts
827
- var getAuthSubscriptionType = () => {
828
- return getCookie("subscriptionType");
829
- };
830
- function convertToBase64(obj) {
831
- try {
832
- if (!obj) return "";
833
- const json = JSON.stringify(obj);
834
- const compressed = pako.deflate(json);
835
- const base64 = Base64.fromUint8Array(compressed, true);
836
- return base64;
837
- } catch (error) {
838
- logger.error("compress", error, { operation: "encode" });
839
- return "";
840
- }
309
+ // src/main/core/utils/param.ts
310
+ function getParam(paramName) {
311
+ if (typeof globalThis === "undefined" || !globalThis.location) return null;
312
+ const hash = globalThis.location.hash || "";
313
+ if (!hash.startsWith("#/")) return null;
314
+ const hashWithoutHash = hash.startsWith("#") ? hash.substring(1) : hash;
315
+ const queryString = hashWithoutHash.split("?")[1];
316
+ if (!queryString) return null;
317
+ const params = new URLSearchParams(queryString);
318
+ return params.get(paramName);
841
319
  }
842
- function decodeToBase64(encoded) {
843
- try {
844
- if (!encoded) return null;
845
- const uint8Array = Base64.toUint8Array(encoded);
846
- const decompressed = pako.inflate(uint8Array, { to: "string" });
847
- return JSON.parse(decompressed);
848
- } catch (error) {
849
- logger.error("compress", error, { operation: "decode" });
850
- return null;
851
- }
320
+ function getPath() {
321
+ if (typeof globalThis === "undefined" || !globalThis.location) return null;
322
+ const hash = globalThis.location.hash || "";
323
+ if (!hash.startsWith("#/")) return null;
324
+ return hash.slice(1).split("?")[0];
852
325
  }
853
326
 
854
- // src/main/features/navigation/url-utils.ts
855
- function mapKeysDeep(obj, keyMap2) {
856
- if (Array.isArray(obj)) {
857
- return obj.map((item) => mapKeysDeep(item, keyMap2));
858
- } else if (obj !== null && typeof obj === "object") {
859
- return Object.entries(obj).reduce(
860
- (acc, [key, value]) => {
861
- const mappedKey = keyMap2[key] || key;
862
- acc[mappedKey] = mapKeysDeep(value, keyMap2);
863
- return acc;
864
- },
865
- {}
866
- );
327
+ // src/main/features/navigation/url.ts
328
+ var updateLink = () => {
329
+ const updateLink2 = async (props, displayName = "prm") => {
330
+ const search = getParam("b");
331
+ const pathname = getPath();
332
+ let breadcrumbs = decodeToBase64(search) || [];
333
+ if (breadcrumbs.length < 1) {
334
+ const routeMenu = getRouteMenu(pathname);
335
+ breadcrumbs = [
336
+ {
337
+ n: routeMenu?.title,
338
+ pt: routeMenu?.path
339
+ }
340
+ ];
341
+ }
342
+ const lastBreadcrumb = breadcrumbs[breadcrumbs.length - 1];
343
+ if (displayName) {
344
+ const ex = await getDeep(lastBreadcrumb, displayName) || {};
345
+ await setDeep(lastBreadcrumb, displayName, {
346
+ ...ex,
347
+ ...props
348
+ });
349
+ } else {
350
+ await Object.assign(lastBreadcrumb, props);
351
+ }
352
+ const newBase64 = convertToBase64(breadcrumbs);
353
+ updateBParam(newBase64);
354
+ };
355
+ function setDeep(obj, path, value) {
356
+ const keys = path.split(".");
357
+ let curr = obj;
358
+ for (let i = 0; i < keys.length - 1; i++) {
359
+ if (!curr[keys[i]] || typeof curr[keys[i]] !== "object") {
360
+ curr[keys[i]] = {};
361
+ }
362
+ curr = curr[keys[i]];
363
+ }
364
+ curr[keys[keys.length - 1]] = value;
365
+ return curr;
867
366
  }
868
- return obj;
869
- }
870
- function isMessingParent(breadcrumbs) {
871
- const lastItem = breadcrumbs[breadcrumbs.length - 1];
872
- const lastItem2 = breadcrumbs[breadcrumbs.length - 2];
873
- const lastItem3 = breadcrumbs[breadcrumbs.length - 3];
874
- return lastItem?.o_r_id && !lastItem2?.o_r_id && lastItem2?.o_t_id && lastItem3?.o_r_id ? true : false;
875
- }
876
- function isMessingParentLastItem(breadcrumbs) {
877
- const lastItem = breadcrumbs[breadcrumbs.length - 1];
878
- const lastItem2 = breadcrumbs[breadcrumbs.length - 2];
879
- return !lastItem?.o_t_id && lastItem2?.o_r_id && lastItem2?.o_t_id ? false : true;
880
- }
881
- function breadcrumbStage(breadcrumbItems) {
882
- let breadcrumbType = "child";
883
- if (breadcrumbItems.length === 1) {
884
- breadcrumbType = "root";
885
- } else if (breadcrumbItems.length === 2) {
886
- breadcrumbType = "root_details";
367
+ function getDeep(obj, path) {
368
+ return path.split(".").reduce((acc, key) => acc?.[key], obj);
887
369
  }
888
- return breadcrumbType;
889
- }
890
- var generateUrl = (props, breadcrumbs) => {
891
- const newBase64 = convertToBase64(breadcrumbs);
892
- let url = "";
893
- if (props?.objectTypeId && props?.recordId) {
894
- url = `/${props?.recordId}/${props?.objectTypeId}/${props?.recordId}?b=${newBase64}`;
895
- } else {
896
- url = `/association/${props?.objectTypeId}?b=${newBase64}`;
370
+ const getLinkParams = (displayName = "prm") => {
371
+ const search = getParam("b");
372
+ const breadcrumbs = decodeToBase64(search) || [];
373
+ if (breadcrumbs.length < 1) return null;
374
+ const lastItem = breadcrumbs[breadcrumbs.length - 1];
375
+ const getDeep2 = (obj, path) => {
376
+ return path.split(".").reduce((acc, key) => acc?.[key], obj);
377
+ };
378
+ const expandKeys = (obj) => {
379
+ return Object.fromEntries(
380
+ Object.entries(obj).map(([key, value]) => [
381
+ keyMap[key] || key,
382
+ // map if exists, else keep original
383
+ value
384
+ ])
385
+ );
386
+ };
387
+ const nestedValue = displayName ? getDeep2(lastItem, displayName) : null;
388
+ const output = nestedValue ? expandKeys(nestedValue) : null;
389
+ return output;
390
+ };
391
+ const filterParams = (displayName = "prm") => {
392
+ const search = getParam("b");
393
+ const breadcrumbs = decodeToBase64(search) || [];
394
+ if (breadcrumbs.length < 1) return null;
395
+ const lastItem = breadcrumbs[breadcrumbs.length - 1];
396
+ const getDeep2 = (obj, path) => {
397
+ return path.split(".").reduce((acc, key) => acc?.[key], obj);
398
+ };
399
+ const expandKeys = (obj) => {
400
+ return Object.fromEntries(
401
+ Object.entries(obj).map(([key, value]) => [
402
+ keyMap[key] || key,
403
+ // map if exists, else keep original
404
+ value
405
+ ])
406
+ );
407
+ };
408
+ const nestedValue = displayName ? getDeep2(lastItem, displayName) : null;
409
+ const output = nestedValue ? expandKeys(nestedValue) : expandKeys(lastItem);
410
+ return output;
411
+ };
412
+ return { updateLink: updateLink2, getLinkParams, filterParams };
413
+ };
414
+ var updateBParam = (newValue) => {
415
+ if (typeof globalThis === "undefined" || !globalThis.location) return;
416
+ const hash = globalThis.location.hash || "";
417
+ if (!hash.startsWith("#/")) return;
418
+ const withoutHash = hash.slice(2);
419
+ const [path, queryString] = withoutHash.split("?");
420
+ const params = new URLSearchParams(queryString || "");
421
+ params.set("b", newValue);
422
+ const newHash = `#/${path}?${params.toString()}`;
423
+ if (typeof globalThis !== "undefined" && globalThis.history && globalThis.history.replaceState) {
424
+ const location = globalThis.location;
425
+ const base = `${location?.pathname ?? ""}${location?.search ?? ""}`;
426
+ globalThis.history.replaceState(null, "", `${base}${newHash}`);
897
427
  }
898
- return url;
899
428
  };
900
- function getTotalParentLength(data) {
901
- return data.filter((item) => (item.pt || item.o_t_id) && !item.o_r_id).length;
902
- }
903
- var generatePath = (breadcrumbs, breadcrumb, index) => {
904
- const bc = convertToBase64(breadcrumbs.slice(0, index + 1));
905
- if (index === 0) {
906
- const pathBase = breadcrumb?.pt || `/${breadcrumb?.o_t_id}`;
907
- const normalizedPath = pathBase.startsWith("/") ? pathBase : `/${pathBase}`;
908
- return {
909
- name: breadcrumb?.n,
910
- path: `${normalizedPath}?b=${bc}`
429
+
430
+ // src/main/state/crm/table-ui-actions.ts
431
+ var pageLimit = 25;
432
+ var boardPaginationDefaults = {
433
+ stageId: "",
434
+ nextPage: 1
435
+ };
436
+ var tableUiActions = {
437
+ setTableUniqueId(v) {
438
+ tableUiStore.setState({ tableUniqueId: v });
439
+ },
440
+ setSort(v) {
441
+ tableUiStore.setState({ sort: v });
442
+ },
443
+ setLimit(v) {
444
+ tableUiStore.setState({ limit: v });
445
+ },
446
+ setAfter(v) {
447
+ tableUiStore.setState({ after: v });
448
+ },
449
+ setPage(v) {
450
+ tableUiStore.setState({ page: v });
451
+ },
452
+ setNextPage(v) {
453
+ tableUiStore.setState({ nextPage: v });
454
+ },
455
+ setStageId(v) {
456
+ tableUiStore.setState({ stageId: v });
457
+ },
458
+ setTotalItems(v) {
459
+ tableUiStore.setState({ totalItems: v });
460
+ },
461
+ setNumOfPages(v) {
462
+ tableUiStore.setState({ numOfPages: v });
463
+ },
464
+ setCurrentPage(v) {
465
+ tableUiStore.setState({ currentPage: v });
466
+ },
467
+ setSearch(v) {
468
+ tableUiStore.setState({ search: v });
469
+ },
470
+ setFilterPropertyName(v) {
471
+ tableUiStore.setState({ filterPropertyName: v });
472
+ },
473
+ setFilterOperator(v) {
474
+ tableUiStore.setState({ filterOperator: v });
475
+ },
476
+ setFilterValue(v) {
477
+ tableUiStore.setState({ filterValue: v });
478
+ },
479
+ setIsPrimaryCompany(v) {
480
+ tableUiStore.setState({ isPrimaryCompany: v });
481
+ },
482
+ setTableFilterData(v) {
483
+ tableUiStore.setState({ tableParam: v });
484
+ },
485
+ setTableDefPermissions(v) {
486
+ tableUiStore.setState({ tableDefPermissions: v });
487
+ },
488
+ setView(mView) {
489
+ tableUiStore.setState({
490
+ page: getAuthSubscriptionType() === "FREE" ? "" : 1,
491
+ view: mView,
492
+ ...boardPaginationDefaults
493
+ });
494
+ },
495
+ changePipeline(mView) {
496
+ tableUiStore.setState({
497
+ page: getAuthSubscriptionType() === "FREE" ? "" : 1,
498
+ selectedPipeline: mView || ""
499
+ });
500
+ },
501
+ setSelectedPipeline(pipelines, pipeLineId) {
502
+ let filterValue = "";
503
+ if (pipeLineId) {
504
+ const pipelineSingle = pipelines.find((pipeline) => pipeline.pipelineId === pipeLineId);
505
+ filterValue = pipelineSingle?.pipelineId || "";
506
+ }
507
+ tableUiStore.setState({
508
+ filterPropertyName: "hs_pipeline",
509
+ filterOperator: "eq",
510
+ filterValue,
511
+ selectedPipeline: filterValue
512
+ });
513
+ },
514
+ resetTableParam() {
515
+ tableUiStore.setState({
516
+ sort: "-hs_createdate",
517
+ limit: pageLimit,
518
+ after: "",
519
+ page: getAuthSubscriptionType() === "FREE" ? "" : 1,
520
+ totalItems: 1,
521
+ numOfPages: 1,
522
+ currentPage: 1,
523
+ search: "",
524
+ filterPropertyName: "hs_pipeline",
525
+ filterOperator: "eq",
526
+ filterValue: "",
527
+ isPrimaryCompany: null,
528
+ selectedPipeline: ""
529
+ });
530
+ },
531
+ getTableParam(companyAsMediator, currentPageOverride) {
532
+ const state = tableUiStore.getState();
533
+ const baseParams = {
534
+ sort: state.sort,
535
+ search: state.search,
536
+ filterPropertyName: state.filterPropertyName,
537
+ filterOperator: state.filterOperator,
538
+ filterValue: state.selectedPipeline,
539
+ cache: true,
540
+ isPrimaryCompany: companyAsMediator || false,
541
+ view: state.view
911
542
  };
912
- } else if (index === 1) {
913
- if (breadcrumb?.isHome) {
543
+ if (getAuthSubscriptionType() === "FREE") {
914
544
  return {
915
- name: breadcrumb?.n,
916
- path: `/association/${breadcrumb?.o_t_id}?b=${bc}`
545
+ ...baseParams,
546
+ after: state.page
917
547
  };
918
548
  }
919
549
  return {
920
- name: breadcrumb?.n,
921
- path: `/${breadcrumb?.o_r_id}/${breadcrumb?.o_t_id}/${breadcrumb?.o_r_id}?b=${bc}`
550
+ ...baseParams,
551
+ limit: state.limit,
552
+ page: currentPageOverride ?? state.page,
553
+ ...state.after ? { after: state.after } : {}
922
554
  };
923
- } else {
924
- if (breadcrumb?.o_t_id && breadcrumb?.o_r_id && !breadcrumb?.isHome) {
925
- return {
926
- name: breadcrumb?.n,
927
- path: `/${breadcrumb?.o_r_id}/${breadcrumb?.o_t_id}/${breadcrumb?.o_r_id}?b=${bc}`
928
- };
929
- } else {
555
+ },
556
+ buildListTableParams(options) {
557
+ return tableUiActions.getTableParam(options?.companyAsMediator, options?.currentPageOverride);
558
+ },
559
+ async setGridData(type, deals) {
560
+ if (type === "reset") {
561
+ tableUiStore.setState({ gridData: [] });
562
+ return [];
563
+ }
564
+ if (type === "directly") {
565
+ tableUiStore.setState({ gridData: deals });
566
+ return deals;
567
+ }
568
+ const finalData = deals.map((deal) => {
569
+ const cards = deal?.data?.results?.rows?.map((row) => ({
570
+ id: row?.hs_object_id,
571
+ ...row,
572
+ hubspotObjectTypeId: type === "deals" ? "0-3" : "0-5"
573
+ })) || [];
930
574
  return {
931
- name: breadcrumb?.n,
932
- path: `/association/${breadcrumb?.o_t_id}?b=${bc}`
575
+ id: deal.id,
576
+ name: deal.label,
577
+ count: deal?.data?.total,
578
+ ...deal,
579
+ cards
933
580
  };
581
+ });
582
+ tableUiStore.setState({ gridData: finalData });
583
+ return finalData;
584
+ },
585
+ setDefaultPipeline(data, hubspotObjectTypeId) {
586
+ if (!data) {
587
+ tableUiStore.setState({ selectedPipeline: "" });
588
+ return "";
934
589
  }
935
- }
936
- };
937
-
938
- // src/main/features/navigation/key-map.ts
939
- var keyMap = {
940
- dp: "defPermissions",
941
- n: "name",
942
- sort: "sort",
943
- o_t_id: "objectTypeId",
944
- s: "search",
945
- fPn: "filterPropertyName",
946
- fO: "filterOperator",
947
- fV: "filterValue",
948
- c: "cache",
949
- isPC: "isPrimaryCompany",
950
- v: "view",
951
- l: "limit",
952
- pt: "path",
953
- p: "page",
954
- a: "after",
955
- aPip: "activePipeline",
956
- aT: "activeTab",
957
- cT: "create",
958
- dP: "display",
959
- dL: "display_label",
960
- pId: "pipeline_id"
590
+ const { updateLink: updateLink2, filterParams } = updateLink();
591
+ const params = filterParams();
592
+ const excludedIds = ["0-1", "0-2", "0-3", "0-4", "0-5", "home"];
593
+ const state = tableUiStore.getState();
594
+ const view = state.view;
595
+ const selectedPipeline = state.selectedPipeline;
596
+ let defaultPipelineId = "";
597
+ let mFilterValue = "";
598
+ const defaultPipeline = data?.data?.[0];
599
+ if (excludedIds.includes(hubspotObjectTypeId)) {
600
+ defaultPipelineId = defaultPipeline?.pipelineId || "";
601
+ }
602
+ if (params && params?.filterPropertyName === "hs_pipeline" && params?.filterValue) {
603
+ mFilterValue = params.filterValue;
604
+ } else if (view === "BOARD" && !selectedPipeline) {
605
+ mFilterValue = defaultPipelineId;
606
+ updateLink2({ fV: defaultPipelineId });
607
+ } else if (!excludedIds.includes(hubspotObjectTypeId)) {
608
+ mFilterValue = selectedPipeline || null;
609
+ } else {
610
+ mFilterValue = data.data.length === 1 ? defaultPipelineId : selectedPipeline;
611
+ }
612
+ tableUiStore.setState({ selectedPipeline: mFilterValue });
613
+ return mFilterValue;
614
+ }
961
615
  };
962
616
 
963
- // src/main/features/navigation/param.ts
964
- var getRouteMenu = (path) => {
965
- const apiRoutes = globalThis?.apiRoutes || [];
966
- return apiRoutes.find((menu) => menu?.path === path);
967
- };
968
- var getRouteDetails = () => {
969
- const search = getParam("b");
970
- const breadcrumbs = decodeToBase64(search) || [];
971
- const lastItem = breadcrumbs[breadcrumbs.length - 1];
972
- const mapped = lastItem ? mapKeysDeep(lastItem, keyMap) : null;
973
- return { routeDetails: mapped };
617
+ // src/main/state/crm/use-form.ts
618
+ var formStore = createStore({
619
+ form: null
620
+ });
621
+ var actions = {
622
+ setFormData(response) {
623
+ formStore.setState({
624
+ form: response
625
+ });
626
+ },
627
+ clearFormData() {
628
+ formStore.setState({
629
+ form: null
630
+ });
631
+ }
974
632
  };
975
- var getParamDetails = (props, isDetailsPage = false) => {
976
- const search = getParam("b");
977
- let breadcrumbs = decodeToBase64(search) || [];
978
- if (breadcrumbs.length > 0 && breadcrumbs?.[0]?.isHome) {
979
- breadcrumbs = breadcrumbs.slice(1);
633
+
634
+ // src/main/state/crm/use-table.ts
635
+ var tableStore = createStore({
636
+ queryParams: null,
637
+ multiObjectsQueryParams: {},
638
+ objectsData: null,
639
+ tableData: [],
640
+ tablePrependData: [],
641
+ hubspotObjectTypeId: "",
642
+ selectedPipeline: "",
643
+ viewType: ""
644
+ });
645
+ function getBoardStagesFromState(state) {
646
+ const fromTable = state.tableData?.data?.results;
647
+ if (Array.isArray(fromTable)) {
648
+ return fromTable;
980
649
  }
981
- let mediatorObjectTypeId = "";
982
- let mediatorObjectRecordId = "";
983
- let parentObjectTypeId = "";
984
- let parentObjectRecordId = "";
985
- const lastItem = breadcrumbs[breadcrumbs.length - 1];
986
- const lastItem2 = breadcrumbs[breadcrumbs.length - 2];
987
- const lastItem3 = breadcrumbs[breadcrumbs.length - 3];
988
- if (isDetailsPage === true && lastItem && "prm" in lastItem) {
989
- delete lastItem.prm;
650
+ const fromObjects = state.objectsData?.data?.results;
651
+ if (Array.isArray(fromObjects)) {
652
+ return fromObjects;
990
653
  }
991
- if (breadcrumbs.length > 1) {
992
- if (props?.type === "ticket" || props?.type === "association") {
993
- mediatorObjectTypeId = breadcrumbs[1]?.o_t_id || "";
994
- mediatorObjectRecordId = breadcrumbs[1]?.o_r_id || "";
995
- if (lastItem?.o_t_id && lastItem?.o_r_id) {
996
- parentObjectTypeId = lastItem?.o_t_id || "";
997
- parentObjectRecordId = lastItem?.o_r_id || "";
998
- } else if (lastItem2?.o_t_id && lastItem2?.o_r_id) {
999
- parentObjectTypeId = lastItem2?.o_t_id || "";
1000
- parentObjectRecordId = lastItem2?.o_r_id || "";
654
+ return [];
655
+ }
656
+ function isBoardStagePageResponse(response) {
657
+ const results = response?.data?.results;
658
+ return response?.info?.viewType === "BOARD" && results != null && !Array.isArray(results);
659
+ }
660
+ function resolveRecordIdFromResponseData(data) {
661
+ if (!data) {
662
+ return void 0;
663
+ }
664
+ const id = data.id ?? data.hs_object_id?.value ?? data.hs_object_id;
665
+ return id != null && id !== "" ? String(id) : void 0;
666
+ }
667
+ function mapResponseFieldsToRowValues(data) {
668
+ return Object.fromEntries(Object.entries(data).map(([key, value]) => [key, value?.value ?? value]));
669
+ }
670
+ function matchRowId(row, recordId) {
671
+ const rowId = row?.id ?? row?.hs_object_id;
672
+ return rowId != null && String(rowId) === recordId;
673
+ }
674
+ function matchHsObjectId(row, recordId) {
675
+ return row?.hs_object_id != null && String(row.hs_object_id) === recordId;
676
+ }
677
+ function mergeRowWithResponseData(row, data) {
678
+ return { ...row, ...mapResponseFieldsToRowValues(data) };
679
+ }
680
+ function patchListRows(rows, data, recordId, matchRow = matchRowId) {
681
+ return rows.map((row) => matchRow(row, recordId) ? mergeRowWithResponseData(row, data) : row);
682
+ }
683
+ function patchBoardStages(stages, data, recordId, matchRow = matchRowId) {
684
+ return stages.map((stage) => ({
685
+ ...stage,
686
+ data: {
687
+ ...stage.data,
688
+ results: {
689
+ ...stage.data?.results,
690
+ rows: patchListRows(stage.data?.results?.rows ?? [], data, recordId, matchRow)
1001
691
  }
1002
- } else {
1003
- if (breadcrumbs.length > 2) {
1004
- mediatorObjectTypeId = breadcrumbs[1]?.o_t_id || "";
1005
- mediatorObjectRecordId = breadcrumbs[1]?.o_r_id || "";
692
+ }
693
+ }));
694
+ }
695
+ function resolveRecordId(payload, data) {
696
+ const payloadId = payload?.params?.id;
697
+ if (payloadId != null && payloadId !== "") {
698
+ return String(payloadId);
699
+ }
700
+ return resolveRecordIdFromResponseData(data);
701
+ }
702
+ var actions2 = {
703
+ /** Called from Client.object.list — feeds purgeCrmListCacheAfterCrmWrite / purgeCrmDetailAndListAfterCrmWrite. */
704
+ setObjectsQueryParams(params) {
705
+ tableStore.setState({
706
+ queryParams: params
707
+ });
708
+ },
709
+ /** Called from Client.object.sideBarList — feeds post-write list purge for sidebarTable writes. */
710
+ setMultiObjectsQueryParams(hubspotObjectTypeId, params) {
711
+ if (!hubspotObjectTypeId) {
712
+ return;
713
+ }
714
+ const state = tableStore.getState();
715
+ tableStore.setState({
716
+ multiObjectsQueryParams: {
717
+ ...state.multiObjectsQueryParams,
718
+ [String(hubspotObjectTypeId)]: params
1006
719
  }
1007
- if (!lastItem?.o_r_id && breadcrumbs.length > 2) {
1008
- parentObjectTypeId = lastItem2?.o_t_id || "";
1009
- parentObjectRecordId = lastItem2?.o_r_id || "";
720
+ });
721
+ },
722
+ async setObjectsData(response, context) {
723
+ const state = tableStore.getState();
724
+ if (response?.info?.viewType == "LIST") {
725
+ tableStore.setState({
726
+ objectsData: response
727
+ });
728
+ }
729
+ if (response?.info?.viewType == "BOARD") {
730
+ const storeStageId = tableUiStore.getState().stageId;
731
+ const stageId = storeStageId !== void 0 && storeStageId !== null && storeStageId !== "" ? storeStageId : context?.stageId;
732
+ if (stageId) {
733
+ const existingResults = state.objectsData?.data?.results;
734
+ if (!Array.isArray(existingResults)) {
735
+ tableStore.setState({
736
+ objectsData: response
737
+ });
738
+ return;
739
+ }
740
+ const boardData = { ...state.objectsData };
741
+ const updatedBoardData = await {
742
+ ...boardData,
743
+ data: {
744
+ ...boardData.data,
745
+ results: boardData.data.results.map(
746
+ (item) => String(item.id) === String(stageId) ? {
747
+ ...item,
748
+ data: {
749
+ ...item.data,
750
+ results: {
751
+ ...item.data.results,
752
+ rows: [
753
+ ...item?.data?.results?.rows ?? [],
754
+ // keep existing rows
755
+ ...response?.data?.results?.rows ?? []
756
+ // prepend new rows
757
+ ]
758
+ }
759
+ }
760
+ } : item
761
+ )
762
+ }
763
+ };
764
+ tableStore.setState({
765
+ objectsData: updatedBoardData
766
+ });
767
+ } else {
768
+ tableStore.setState({
769
+ objectsData: response
770
+ });
1010
771
  }
1011
- if (lastItem?.o_r_id && breadcrumbs.length > 2) {
1012
- parentObjectTypeId = lastItem3?.o_t_id || "";
1013
- parentObjectRecordId = lastItem3?.o_r_id || "";
772
+ }
773
+ },
774
+ setTableData(response, payload) {
775
+ const state = tableStore.getState();
776
+ const viewType = response?.info?.viewType;
777
+ let newTablePrependData;
778
+ if (viewType === "BOARD") {
779
+ const stages = Array.isArray(response?.data?.results) ? response.data.results : getBoardStagesFromState(state);
780
+ newTablePrependData = state.tablePrependData.map((prependStage) => {
781
+ const matchingStage = stages.find((stage) => String(stage.id) === String(prependStage.id));
782
+ const rows = matchingStage?.data?.results?.rows ?? [];
783
+ const rowIds = new Set(
784
+ rows.map((row) => row.id ?? row.hs_object_id).filter((id) => id != null && id !== "").map((id) => String(id))
785
+ );
786
+ const filteredRows = (prependStage?.data?.results?.rows ?? []).filter((item) => {
787
+ const itemId = item.id ?? item.hs_object_id;
788
+ if (itemId == null || itemId === "") return true;
789
+ return !rowIds.has(String(itemId));
790
+ });
791
+ return {
792
+ ...prependStage,
793
+ data: {
794
+ ...prependStage.data,
795
+ results: {
796
+ ...prependStage.data?.results,
797
+ rows: filteredRows
798
+ }
799
+ }
800
+ };
801
+ });
802
+ } else {
803
+ const rows = response?.data?.results?.rows ?? [];
804
+ const rowIds = new Set(
805
+ rows.map((row) => row.id ?? row.hs_object_id).filter((id) => id != null && id !== "").map((id) => String(id))
806
+ );
807
+ newTablePrependData = state.tablePrependData.filter((item) => {
808
+ const itemId = item.id ?? item.hs_object_id;
809
+ if (itemId == null || itemId === "") return true;
810
+ return !rowIds.has(String(itemId));
811
+ });
812
+ }
813
+ const hubspotObjectTypeId = payload?.hubspotObjectTypeId;
814
+ const selectedPipeline = payload?.selectedPipeline;
815
+ if (response?.data?.total < 1 || payload?.componentName) {
816
+ newTablePrependData = [];
817
+ }
818
+ if (state.viewType && state.viewType != viewType) {
819
+ newTablePrependData = [];
820
+ }
821
+ if (state.hubspotObjectTypeId && state.hubspotObjectTypeId != hubspotObjectTypeId) {
822
+ newTablePrependData = [];
823
+ }
824
+ if (state.selectedPipeline && state.selectedPipeline != selectedPipeline) {
825
+ newTablePrependData = [];
826
+ }
827
+ if (payload.isFristTimeLoadData) {
828
+ newTablePrependData = [];
829
+ }
830
+ const preserveBoardTableData = isBoardStagePageResponse(response) && state.tableData?.info?.viewType === "BOARD" && Array.isArray(state.tableData?.data?.results);
831
+ tableStore.setState({
832
+ tableData: preserveBoardTableData ? state.tableData : response,
833
+ tablePrependData: newTablePrependData || [],
834
+ hubspotObjectTypeId,
835
+ viewType
836
+ });
837
+ },
838
+ modifiedObjectsData(results) {
839
+ const state = tableStore.getState();
840
+ const tablePrependData = state.tablePrependData;
841
+ const modifiedData = results.map((result) => {
842
+ const matchedPrepend = tablePrependData.find((item) => String(item?.id) === String(result?.id));
843
+ if (!matchedPrepend) {
844
+ return result;
845
+ }
846
+ const prependRows = matchedPrepend?.data?.results?.rows ?? [];
847
+ const prependCards = prependRows.map((row) => ({
848
+ id: row.hs_object_id,
849
+ ...row
850
+ }));
851
+ return {
852
+ ...result,
853
+ // prepend in results.rows
854
+ data: {
855
+ ...result.data,
856
+ results: {
857
+ ...result.data.results,
858
+ rows: [...prependRows, ...result?.data?.results?.rows ?? []]
859
+ }
860
+ },
861
+ // prepend in cards
862
+ cards: [...prependCards, ...result?.cards ?? []]
863
+ };
864
+ });
865
+ tableStore.setState({
866
+ objectsData: modifiedData
867
+ });
868
+ },
869
+ clearTablePrependData() {
870
+ tableStore.setState({
871
+ tablePrependData: []
872
+ });
873
+ },
874
+ async setTablePrependData(response, props) {
875
+ const state = tableStore.getState();
876
+ const formState = formStore.getState();
877
+ let rows = [];
878
+ if (state.tableData?.info?.viewType == "BOARD") {
879
+ if (response === "loading") {
880
+ const responseData = getBoardStagesFromState(state);
881
+ const pipelineStage = props?.payload?.propertyPayload?.hs_pipeline_stage || props?.payload?.propertyPayload?.dealstage || formState?.form?.data?.pipelineDefaults?.defaultStage?.id;
882
+ rows = responseData.map(({ id, data }) => {
883
+ const matchedPrepend = state.tablePrependData.find((item) => String(item.id) === String(id));
884
+ const prependRows = matchedPrepend?.data?.results?.rows ?? [];
885
+ const newRow = String(id) === String(pipelineStage) ? [
886
+ (data?.results?.columns ?? []).reduce((obj, column) => {
887
+ obj[column.key] = "loading";
888
+ return obj;
889
+ }, {})
890
+ ] : [];
891
+ return {
892
+ id,
893
+ data: {
894
+ results: {
895
+ columns: data?.results?.columns ?? [],
896
+ // prepend loading row + prepend rows
897
+ rows: [...newRow, ...prependRows]
898
+ }
899
+ }
900
+ };
901
+ });
902
+ } else {
903
+ const data = response?.data;
904
+ const hs_pipeline_stage = data?.hs_pipeline_stage?.value?.value || data?.dealstage?.value?.value;
905
+ if (!data) {
906
+ tableStore.setState({
907
+ tablePrependData: []
908
+ });
909
+ }
910
+ rows = state?.tablePrependData.map((row) => {
911
+ const matchedPrepend = state.tablePrependData.find((item) => String(item.id) === String(row.id));
912
+ const prependRows = matchedPrepend?.data?.results?.rows ?? [];
913
+ if (String(row.id) === String(hs_pipeline_stage)) {
914
+ const updatedRow = (row?.data?.results?.columns ?? []).reduce((obj, column) => {
915
+ const key = column.key;
916
+ obj[key] = data?.[key]?.value ?? data?.[key] ?? "";
917
+ return obj;
918
+ }, {});
919
+ prependRows[0] = updatedRow;
920
+ return {
921
+ ...row,
922
+ data: {
923
+ ...row.data,
924
+ results: {
925
+ ...row.data.results,
926
+ rows: prependRows
927
+ }
928
+ }
929
+ };
930
+ }
931
+ return row;
932
+ });
1014
933
  }
1015
- if (lastItem2?.o_t_id === "0-5" && !parentObjectTypeId && !parentObjectRecordId) {
1016
- parentObjectTypeId = lastItem2?.o_t_id || "";
1017
- parentObjectRecordId = lastItem2?.o_r_id || "";
934
+ } else if (state.tableData?.info?.viewType == "LIST") {
935
+ if (response === "loading") {
936
+ const row = await state.tableData?.data?.results?.columns.reduce((acc, item) => {
937
+ if (!item.hidden) {
938
+ acc[item.key] = "loading";
939
+ }
940
+ return acc;
941
+ }, {});
942
+ rows = [row, ...state.tablePrependData];
943
+ } else if (response?.data) {
944
+ const data = response?.data;
945
+ if (!data) {
946
+ tableStore.setState({
947
+ tablePrependData: []
948
+ });
949
+ }
950
+ const row = await Object.fromEntries(Object.entries(data).map(([key, value]) => [key, value?.value ?? value]));
951
+ rows = [...state.tablePrependData];
952
+ if (rows.length > 0) {
953
+ rows[0] = row;
954
+ } else {
955
+ rows.push(row);
956
+ }
1018
957
  }
1019
958
  }
1020
- }
1021
- const paramsObject = {};
1022
- if (breadcrumbs[0]?.prm?.isPC || breadcrumbs[1]?.prm?.isPC || lastItem?.prm?.isPC) {
1023
- paramsObject["isPrimaryCompany"] = true;
1024
- }
1025
- if (parentObjectTypeId && parentObjectRecordId) {
1026
- paramsObject["parentObjectTypeId"] = parentObjectTypeId;
1027
- paramsObject["parentObjectRecordId"] = parentObjectRecordId;
1028
- }
1029
- if (mediatorObjectTypeId && mediatorObjectRecordId) {
1030
- paramsObject["mediatorObjectTypeId"] = mediatorObjectTypeId;
1031
- paramsObject["mediatorObjectRecordId"] = mediatorObjectRecordId;
1032
- }
1033
- const mappedLastItemParam = Object.fromEntries(
1034
- Object.entries(lastItem?.prm || {}).map(([key, value]) => [
1035
- keyMap[key] || key,
1036
- // use mapped name if exists, else keep original
1037
- value
1038
- ])
1039
- );
1040
- let queryString = null;
1041
- if (props?.type === "association") {
1042
- queryString = new URLSearchParams({ ...paramsObject, ...{ cache: false } }).toString();
1043
- } else {
1044
- queryString = new URLSearchParams({ ...paramsObject, ...mappedLastItemParam }).toString();
1045
- }
1046
- const params = queryString ? `?${queryString}` : "";
1047
- const totalParentLength = getTotalParentLength(breadcrumbs);
1048
- let parentAccessLabel = false;
1049
- if (breadcrumbs[0]?.prm?.isPC && totalParentLength > 2 || // company object
1050
- !breadcrumbs[0]?.prm?.isPC && totalParentLength > 3 || // normal object
1051
- breadcrumbs[0]?.prm?.isPC && totalParentLength > 1 && props?.type === "ticket" || // company ticket
1052
- !breadcrumbs[0]?.prm?.isPC && totalParentLength > 2 && props?.type === "ticket") {
1053
- parentAccessLabel = true;
1054
- }
1055
- return {
1056
- breadcrumbs,
1057
- // paramsObject: Object.keys(mParamsObject).length === 0 ? null : mParamsObject,
1058
- paramsObject,
1059
- params,
1060
- parentAccessLabel
1061
- };
1062
- };
1063
-
1064
- // src/main/core/utils/url.ts
1065
- var ticketHubspotObjectTypeId = () => {
1066
- const paramDetails = getParamDetails();
1067
- if (
1068
- // this hubspotObjectTypeId only for main contact ticket object type
1069
- paramDetails?.breadcrumbs?.length === 2 && paramDetails?.breadcrumbs[0]?.pt === "/0-5"
1070
- ) {
1071
- return "0-1";
1072
- }
1073
- if (
1074
- // this hubspotObjectTypeId only for main company ticket object type
1075
- paramDetails?.breadcrumbs?.length === 2 && paramDetails?.breadcrumbs[0]?.pt === "/0-5-c"
1076
- ) {
1077
- return "0-2";
1078
- }
1079
- return "";
1080
- };
1081
-
1082
- // src/main/core/utils/param.ts
1083
- function getParam(paramName) {
1084
- if (typeof globalThis === "undefined" || !globalThis.location) return null;
1085
- const hash = globalThis.location.hash || "";
1086
- if (!hash.startsWith("#/")) return null;
1087
- const hashWithoutHash = hash.startsWith("#") ? hash.substring(1) : hash;
1088
- const queryString = hashWithoutHash.split("?")[1];
1089
- if (!queryString) return null;
1090
- const params = new URLSearchParams(queryString);
1091
- return params.get(paramName);
1092
- }
1093
- function getPath() {
1094
- if (typeof globalThis === "undefined" || !globalThis.location) return null;
1095
- const hash = globalThis.location.hash || "";
1096
- if (!hash.startsWith("#/")) return null;
1097
- return hash.slice(1).split("?")[0];
1098
- }
1099
-
1100
- // src/main/features/navigation/url.ts
1101
- var updateLink = () => {
1102
- const updateLink2 = async (props, displayName = "prm") => {
1103
- const search = getParam("b");
1104
- const pathname = getPath();
1105
- let breadcrumbs = decodeToBase64(search) || [];
1106
- if (breadcrumbs.length < 1) {
1107
- const routeMenu = getRouteMenu(pathname);
1108
- breadcrumbs = [
1109
- {
1110
- n: routeMenu?.title,
1111
- pt: routeMenu?.path
1112
- }
1113
- ];
959
+ tableStore.setState({
960
+ tablePrependData: rows
961
+ });
962
+ },
963
+ updateTablePrependData(response, payload) {
964
+ const data = response?.data;
965
+ const recordId = resolveRecordId(payload, data);
966
+ if (!data || !recordId) {
967
+ return response;
1114
968
  }
1115
- const lastBreadcrumb = breadcrumbs[breadcrumbs.length - 1];
1116
- if (displayName) {
1117
- const ex = await getDeep(lastBreadcrumb, displayName) || {};
1118
- await setDeep(lastBreadcrumb, displayName, {
1119
- ...ex,
1120
- ...props
1121
- });
969
+ const state = tableStore.getState();
970
+ const viewType = state.tableData?.info?.viewType ?? state.viewType;
971
+ const objectsDataMatcher = payload?.params?.id != null && payload.params.id !== "" ? matchHsObjectId : matchRowId;
972
+ let tablePrependData = state.tablePrependData;
973
+ if (viewType === "BOARD") {
974
+ tablePrependData = patchBoardStages(state.tablePrependData, data, recordId);
1122
975
  } else {
1123
- await Object.assign(lastBreadcrumb, props);
976
+ tablePrependData = patchListRows(state.tablePrependData, data, recordId);
1124
977
  }
1125
- const newBase64 = convertToBase64(breadcrumbs);
1126
- updateBParam(newBase64);
1127
- };
1128
- function setDeep(obj, path, value) {
1129
- const keys = path.split(".");
1130
- let curr = obj;
1131
- for (let i = 0; i < keys.length - 1; i++) {
1132
- if (!curr[keys[i]] || typeof curr[keys[i]] !== "object") {
1133
- curr[keys[i]] = {};
978
+ const stateUpdates = { tablePrependData };
979
+ const patchListResponse = (cached, matchRow = matchRowId) => {
980
+ const rows = cached?.data?.results?.rows ?? cached?.results?.rows;
981
+ if (!rows) {
982
+ return cached;
1134
983
  }
1135
- curr = curr[keys[i]];
1136
- }
1137
- curr[keys[keys.length - 1]] = value;
1138
- return curr;
1139
- }
1140
- function getDeep(obj, path) {
1141
- return path.split(".").reduce((acc, key) => acc?.[key], obj);
1142
- }
1143
- const getLinkParams = (displayName = "prm") => {
1144
- const search = getParam("b");
1145
- const breadcrumbs = decodeToBase64(search) || [];
1146
- if (breadcrumbs.length < 1) return null;
1147
- const lastItem = breadcrumbs[breadcrumbs.length - 1];
1148
- const getDeep2 = (obj, path) => {
1149
- return path.split(".").reduce((acc, key) => acc?.[key], obj);
1150
- };
1151
- const expandKeys = (obj) => {
1152
- return Object.fromEntries(
1153
- Object.entries(obj).map(([key, value]) => [
1154
- keyMap[key] || key,
1155
- // map if exists, else keep original
1156
- value
1157
- ])
1158
- );
1159
- };
1160
- const nestedValue = displayName ? getDeep2(lastItem, displayName) : null;
1161
- const output = nestedValue ? expandKeys(nestedValue) : null;
1162
- return output;
1163
- };
1164
- const filterParams = (displayName = "prm") => {
1165
- const search = getParam("b");
1166
- const breadcrumbs = decodeToBase64(search) || [];
1167
- if (breadcrumbs.length < 1) return null;
1168
- const lastItem = breadcrumbs[breadcrumbs.length - 1];
1169
- const getDeep2 = (obj, path) => {
1170
- return path.split(".").reduce((acc, key) => acc?.[key], obj);
984
+ const patchedRows = patchListRows(rows, data, recordId, matchRow);
985
+ if (cached?.data?.results?.rows) {
986
+ return {
987
+ ...cached,
988
+ data: {
989
+ ...cached.data,
990
+ results: {
991
+ ...cached.data.results,
992
+ rows: patchedRows
993
+ }
994
+ }
995
+ };
996
+ }
997
+ return {
998
+ ...cached,
999
+ results: {
1000
+ ...cached.results,
1001
+ rows: patchedRows
1002
+ }
1003
+ };
1171
1004
  };
1172
- const expandKeys = (obj) => {
1173
- return Object.fromEntries(
1174
- Object.entries(obj).map(([key, value]) => [
1175
- keyMap[key] || key,
1176
- // map if exists, else keep original
1177
- value
1178
- ])
1179
- );
1005
+ const patchBoardResponse = (cached, matchRow = matchRowId) => {
1006
+ if (!Array.isArray(cached?.data?.results)) {
1007
+ return cached;
1008
+ }
1009
+ return {
1010
+ ...cached,
1011
+ data: {
1012
+ ...cached.data,
1013
+ results: patchBoardStages(cached.data.results, data, recordId, matchRow)
1014
+ }
1015
+ };
1180
1016
  };
1181
- const nestedValue = displayName ? getDeep2(lastItem, displayName) : null;
1182
- const output = nestedValue ? expandKeys(nestedValue) : expandKeys(lastItem);
1183
- return output;
1184
- };
1185
- return { updateLink: updateLink2, getLinkParams, filterParams };
1186
- };
1187
- var updateBParam = (newValue) => {
1188
- if (typeof globalThis === "undefined" || !globalThis.location) return;
1189
- const hash = globalThis.location.hash || "";
1190
- if (!hash.startsWith("#/")) return;
1191
- const withoutHash = hash.slice(2);
1192
- const [path, queryString] = withoutHash.split("?");
1193
- const params = new URLSearchParams(queryString || "");
1194
- params.set("b", newValue);
1195
- const newHash = `#/${path}?${params.toString()}`;
1196
- if (typeof globalThis !== "undefined" && globalThis.history && globalThis.history.replaceState) {
1197
- const location = globalThis.location;
1198
- const base = `${location?.pathname ?? ""}${location?.search ?? ""}`;
1199
- globalThis.history.replaceState(null, "", `${base}${newHash}`);
1017
+ if (state.objectsData) {
1018
+ stateUpdates.objectsData = viewType === "BOARD" ? patchBoardResponse(state.objectsData, objectsDataMatcher) : patchListResponse(state.objectsData, objectsDataMatcher);
1019
+ }
1020
+ if (state.tableData) {
1021
+ stateUpdates.tableData = viewType === "BOARD" ? patchBoardResponse(state.tableData) : patchListResponse(state.tableData);
1022
+ }
1023
+ tableStore.setState(stateUpdates);
1024
+ return response;
1200
1025
  }
1201
1026
  };
1202
1027
 
1203
- // src/main/state/crm/table-ui-actions.ts
1204
- var pageLimit = 25;
1205
- var boardPaginationDefaults = {
1206
- stageId: "",
1207
- nextPage: 1
1208
- };
1209
- var tableUiActions = {
1210
- setTableUniqueId(v) {
1211
- tableUiStore.setState({ tableUniqueId: v });
1212
- },
1213
- setSort(v) {
1214
- tableUiStore.setState({ sort: v });
1215
- },
1216
- setLimit(v) {
1217
- tableUiStore.setState({ limit: v });
1218
- },
1219
- setAfter(v) {
1220
- tableUiStore.setState({ after: v });
1221
- },
1222
- setPage(v) {
1223
- tableUiStore.setState({ page: v });
1224
- },
1225
- setNextPage(v) {
1226
- tableUiStore.setState({ nextPage: v });
1227
- },
1228
- setStageId(v) {
1229
- tableUiStore.setState({ stageId: v });
1230
- },
1231
- setTotalItems(v) {
1232
- tableUiStore.setState({ totalItems: v });
1233
- },
1234
- setNumOfPages(v) {
1235
- tableUiStore.setState({ numOfPages: v });
1236
- },
1237
- setCurrentPage(v) {
1238
- tableUiStore.setState({ currentPage: v });
1239
- },
1240
- setSearch(v) {
1241
- tableUiStore.setState({ search: v });
1242
- },
1243
- setFilterPropertyName(v) {
1244
- tableUiStore.setState({ filterPropertyName: v });
1245
- },
1246
- setFilterOperator(v) {
1247
- tableUiStore.setState({ filterOperator: v });
1028
+ // src/main/state/crm/use-uploader.ts
1029
+ var uploaderStore = createStore({
1030
+ attachments: []
1031
+ });
1032
+ function toAttachmentSummary(attachment) {
1033
+ return {
1034
+ createdAt: attachment.createdAt,
1035
+ id: attachment.id,
1036
+ name: attachment.name,
1037
+ size: attachment.size,
1038
+ type: attachment.type,
1039
+ updatedAt: attachment.updatedAt
1040
+ };
1041
+ }
1042
+ function resolveAttachmentsFromIds(attachmentIds, storedAttachments) {
1043
+ const raw = typeof attachmentIds === "object" && attachmentIds !== null && "value" in attachmentIds ? attachmentIds.value : attachmentIds;
1044
+ const ids = String(raw ?? "").split(";").map((id) => id.trim()).filter(Boolean);
1045
+ return ids.map((id) => storedAttachments.find((a) => String(a.id) === id)).filter((a) => a != null).map(toAttachmentSummary);
1046
+ }
1047
+ var actions3 = {
1048
+ setAttachment(response) {
1049
+ const data = response?.data;
1050
+ if (!data?.id) return;
1051
+ const state = uploaderStore.getState();
1052
+ const id = String(data.id);
1053
+ const existing = state.attachments;
1054
+ const index = existing.findIndex((item) => String(item.id) === id);
1055
+ const attachments = index >= 0 ? existing.map((item, i) => i === index ? data : item) : [...existing, data];
1056
+ uploaderStore.setState({ attachments });
1248
1057
  },
1249
- setFilterValue(v) {
1250
- tableUiStore.setState({ filterValue: v });
1058
+ clearAttachments() {
1059
+ uploaderStore.setState({ attachments: [] });
1060
+ }
1061
+ };
1062
+
1063
+ // src/main/state/crm/use-note.ts
1064
+ var noteStore = createStore({
1065
+ notes: [],
1066
+ prependNotes: [],
1067
+ id: "",
1068
+ queryParams: null
1069
+ });
1070
+ var actions4 = {
1071
+ /** Called from Client.note.list — feeds purgeEngagementCaches (view: notes). */
1072
+ setListQueryParams(params) {
1073
+ noteStore.setState({
1074
+ queryParams: params
1075
+ });
1251
1076
  },
1252
- setIsPrimaryCompany(v) {
1253
- tableUiStore.setState({ isPrimaryCompany: v });
1077
+ setNotes(response, payload) {
1078
+ const state = noteStore.getState();
1079
+ const rows = response?.data?.results?.rows ?? [];
1080
+ const rowIds = new Set(
1081
+ rows.map((row) => row.id ?? row.hs_object_id).filter((id2) => id2 != null && id2 !== "").map((id2) => String(id2))
1082
+ );
1083
+ let newPrependNotes = state.prependNotes.filter((item) => {
1084
+ const itemId = item.id ?? item.hs_object_id;
1085
+ if (itemId == null || itemId === "") return true;
1086
+ return !rowIds.has(String(itemId));
1087
+ });
1088
+ const id = payload?.params?.id;
1089
+ if (state.id && state.id != id) {
1090
+ newPrependNotes = [];
1091
+ }
1092
+ noteStore.setState({
1093
+ notes: response,
1094
+ prependNotes: newPrependNotes,
1095
+ id
1096
+ });
1254
1097
  },
1255
- setTableFilterData(v) {
1256
- tableUiStore.setState({ tableParam: v });
1098
+ async setPrependNote(response) {
1099
+ const state = noteStore.getState();
1100
+ let rows = [];
1101
+ if (response === "loading") {
1102
+ const row = await state.notes?.data?.results?.columns.reduce((acc, item) => {
1103
+ if (!item.hidden) {
1104
+ acc[item.key] = "loading";
1105
+ }
1106
+ return acc;
1107
+ }, {});
1108
+ rows = [row, ...state.prependNotes];
1109
+ } else if (response?.data) {
1110
+ const data = response?.data;
1111
+ if (!data) {
1112
+ noteStore.setState({
1113
+ prependNotes: []
1114
+ });
1115
+ }
1116
+ const storedAttachments = uploaderStore.getState().attachments;
1117
+ const row = Object.fromEntries(
1118
+ Object.entries(data).map(([key, value]) => {
1119
+ if (key === "hs_attachment_ids") {
1120
+ return [key, resolveAttachmentsFromIds(value, storedAttachments)];
1121
+ }
1122
+ return [key, value?.value ?? value];
1123
+ })
1124
+ );
1125
+ rows = [...state.prependNotes];
1126
+ if (rows.length > 0) {
1127
+ rows[0] = row;
1128
+ } else {
1129
+ rows.push(row);
1130
+ }
1131
+ }
1132
+ noteStore.setState({
1133
+ prependNotes: rows
1134
+ });
1257
1135
  },
1258
- setTableDefPermissions(v) {
1259
- tableUiStore.setState({ tableDefPermissions: v });
1136
+ clearPrependNotes() {
1137
+ noteStore.setState({
1138
+ prependNotes: []
1139
+ });
1140
+ actions3.clearAttachments();
1260
1141
  },
1261
- setView(mView) {
1262
- tableUiStore.setState({
1263
- page: getAuthSubscriptionType() === "FREE" ? "" : 1,
1264
- view: mView,
1265
- ...boardPaginationDefaults
1142
+ async updatePrependNote(response) {
1143
+ const responseData = { ...response };
1144
+ const state = noteStore.getState();
1145
+ const prependNotes = state.prependNotes || [];
1146
+ const note = response.data || null;
1147
+ const storedAttachments = uploaderStore.getState().attachments;
1148
+ const notes = prependNotes.map(
1149
+ (item) => item?.hs_object_id === note?.hs_object_id?.value ? {
1150
+ ...item,
1151
+ ...Object.fromEntries(
1152
+ Object.entries(note).map(([key, value]) => {
1153
+ if (key === "hs_attachment_ids") {
1154
+ return [key, resolveAttachmentsFromIds(value, storedAttachments)];
1155
+ }
1156
+ return [key, value?.value ?? value];
1157
+ })
1158
+ )
1159
+ } : item
1160
+ );
1161
+ noteStore.setState({
1162
+ prependNotes: notes
1163
+ });
1164
+ if (responseData?.data?.hs_attachment_ids != null) {
1165
+ const noteObjectId = note?.hs_object_id?.value;
1166
+ const rows = state.notes?.data?.results?.rows ?? [];
1167
+ const matchingRow = rows.find((row) => String(row.hs_object_id) === String(noteObjectId));
1168
+ const originalPrependItem = notes.find((item) => String(item?.hs_object_id) === String(noteObjectId));
1169
+ const existingAttachments = matchingRow?.hs_attachment_ids ?? originalPrependItem?.hs_attachment_ids ?? [];
1170
+ const newAttachments = resolveAttachmentsFromIds(responseData.data.hs_attachment_ids, storedAttachments);
1171
+ const mergedAttachments = [
1172
+ ...existingAttachments,
1173
+ ...newAttachments.filter((attachment) => !existingAttachments.some((existing) => String(existing.id) === String(attachment.id)))
1174
+ ];
1175
+ const stateUpdates = {};
1176
+ if (matchingRow && state.notes?.data?.results) {
1177
+ stateUpdates.notes = {
1178
+ ...state.notes,
1179
+ data: {
1180
+ ...state.notes.data,
1181
+ results: {
1182
+ ...state.notes.data.results,
1183
+ rows: rows.map(
1184
+ (row) => String(row.hs_object_id) === String(noteObjectId) ? { ...row, hs_attachment_ids: mergedAttachments } : row
1185
+ )
1186
+ }
1187
+ }
1188
+ };
1189
+ }
1190
+ if (originalPrependItem) {
1191
+ stateUpdates.prependNotes = notes.map(
1192
+ (item) => String(item?.hs_object_id) === String(noteObjectId) ? { ...item, hs_attachment_ids: mergedAttachments } : item
1193
+ );
1194
+ }
1195
+ if (Object.keys(stateUpdates).length > 0) {
1196
+ noteStore.setState(stateUpdates);
1197
+ }
1198
+ responseData.data.hs_attachment_ids = mergedAttachments;
1199
+ }
1200
+ return responseData;
1201
+ }
1202
+ };
1203
+
1204
+ // src/main/state/crm/use-email.ts
1205
+ var emailStore = createStore({
1206
+ emails: [],
1207
+ prependEmails: [],
1208
+ id: "",
1209
+ queryParams: null
1210
+ });
1211
+ var actions5 = {
1212
+ /** Called from Client.email.list — feeds purgeEngagementCaches (view: emails). */
1213
+ setListQueryParams(params) {
1214
+ emailStore.setState({
1215
+ queryParams: params
1266
1216
  });
1267
1217
  },
1268
- changePipeline(mView) {
1269
- tableUiStore.setState({
1270
- page: getAuthSubscriptionType() === "FREE" ? "" : 1,
1271
- selectedPipeline: mView || ""
1218
+ setEmails(response, payload) {
1219
+ const state = emailStore.getState();
1220
+ const rows = response?.data?.results?.rows ?? [];
1221
+ const rowIds = new Set(
1222
+ rows.map((row) => row.id ?? row.hs_object_id).filter((id2) => id2 != null && id2 !== "").map((id2) => String(id2))
1223
+ );
1224
+ let newPrependEmails = state.prependEmails.filter((item) => {
1225
+ const itemId = item.id ?? item.hs_object_id;
1226
+ if (itemId == null || itemId === "") return true;
1227
+ return !rowIds.has(String(itemId));
1272
1228
  });
1273
- },
1274
- setSelectedPipeline(pipelines, pipeLineId) {
1275
- let filterValue = "";
1276
- if (pipeLineId) {
1277
- const pipelineSingle = pipelines.find((pipeline) => pipeline.pipelineId === pipeLineId);
1278
- filterValue = pipelineSingle?.pipelineId || "";
1229
+ const id = payload?.params?.id;
1230
+ if (state.id && state.id != id) {
1231
+ newPrependEmails = [];
1279
1232
  }
1280
- tableUiStore.setState({
1281
- filterPropertyName: "hs_pipeline",
1282
- filterOperator: "eq",
1283
- filterValue,
1284
- selectedPipeline: filterValue
1285
- });
1286
- },
1287
- resetTableParam() {
1288
- tableUiStore.setState({
1289
- sort: "-hs_createdate",
1290
- limit: pageLimit,
1291
- after: "",
1292
- page: getAuthSubscriptionType() === "FREE" ? "" : 1,
1293
- totalItems: 1,
1294
- numOfPages: 1,
1295
- currentPage: 1,
1296
- search: "",
1297
- filterPropertyName: "hs_pipeline",
1298
- filterOperator: "eq",
1299
- filterValue: "",
1300
- isPrimaryCompany: null,
1301
- selectedPipeline: ""
1233
+ emailStore.setState({
1234
+ emails: response,
1235
+ prependEmails: newPrependEmails,
1236
+ id
1302
1237
  });
1303
1238
  },
1304
- getTableParam(companyAsMediator, currentPageOverride) {
1305
- const state = tableUiStore.getState();
1306
- const baseParams = {
1307
- sort: state.sort,
1308
- search: state.search,
1309
- filterPropertyName: state.filterPropertyName,
1310
- filterOperator: state.filterOperator,
1311
- filterValue: state.selectedPipeline,
1312
- cache: true,
1313
- isPrimaryCompany: companyAsMediator || false,
1314
- view: state.view
1315
- };
1316
- if (getAuthSubscriptionType() === "FREE") {
1317
- return {
1318
- ...baseParams,
1319
- after: state.page
1320
- };
1239
+ async setPrependEmail(response) {
1240
+ const state = emailStore.getState();
1241
+ let rows = [];
1242
+ if (response === "loading") {
1243
+ const row = await state.emails?.data?.results?.columns.reduce((acc, item) => {
1244
+ if (!item.hidden) {
1245
+ acc[item.key] = "loading";
1246
+ }
1247
+ return acc;
1248
+ }, {});
1249
+ rows = [row, ...state.prependEmails];
1250
+ } else if (response?.data) {
1251
+ const data = response?.data;
1252
+ if (!data) {
1253
+ emailStore.setState({
1254
+ prependEmails: []
1255
+ });
1256
+ }
1257
+ const storedAttachments = uploaderStore.getState().attachments;
1258
+ const row = Object.fromEntries(
1259
+ Object.entries(data).map(([key, value]) => {
1260
+ if (key === "hs_attachment_ids") {
1261
+ return [key, resolveAttachmentsFromIds(value, storedAttachments)];
1262
+ }
1263
+ return [key, value?.value ?? value];
1264
+ })
1265
+ );
1266
+ rows = [...state.prependEmails];
1267
+ if (rows.length > 0) {
1268
+ rows[0] = row;
1269
+ } else {
1270
+ rows.push(row);
1271
+ }
1321
1272
  }
1322
- return {
1323
- ...baseParams,
1324
- limit: state.limit,
1325
- page: currentPageOverride ?? state.page,
1326
- ...state.after ? { after: state.after } : {}
1327
- };
1328
- },
1329
- buildListTableParams(options) {
1330
- return tableUiActions.getTableParam(options?.companyAsMediator, options?.currentPageOverride);
1273
+ emailStore.setState({
1274
+ prependEmails: rows
1275
+ });
1331
1276
  },
1332
- async setGridData(type, deals) {
1333
- if (type === "reset") {
1334
- tableUiStore.setState({ gridData: [] });
1335
- return [];
1336
- }
1337
- if (type === "directly") {
1338
- tableUiStore.setState({ gridData: deals });
1339
- return deals;
1340
- }
1341
- const finalData = deals.map((deal) => {
1342
- const cards = deal?.data?.results?.rows?.map((row) => ({
1343
- id: row?.hs_object_id,
1344
- ...row,
1345
- hubspotObjectTypeId: type === "deals" ? "0-3" : "0-5"
1346
- })) || [];
1347
- return {
1348
- id: deal.id,
1349
- name: deal.label,
1350
- count: deal?.data?.total,
1351
- ...deal,
1352
- cards
1353
- };
1277
+ clearPrependEmails() {
1278
+ emailStore.setState({
1279
+ prependEmails: []
1354
1280
  });
1355
- tableUiStore.setState({ gridData: finalData });
1356
- return finalData;
1281
+ actions3.clearAttachments();
1357
1282
  },
1358
- setDefaultPipeline(data, hubspotObjectTypeId) {
1359
- if (!data) {
1360
- tableUiStore.setState({ selectedPipeline: "" });
1361
- return "";
1362
- }
1363
- const { updateLink: updateLink2, filterParams } = updateLink();
1364
- const params = filterParams();
1365
- const excludedIds = ["0-1", "0-2", "0-3", "0-4", "0-5", "home"];
1366
- const state = tableUiStore.getState();
1367
- const view = state.view;
1368
- const selectedPipeline = state.selectedPipeline;
1369
- let defaultPipelineId = "";
1370
- let mFilterValue = "";
1371
- const defaultPipeline = data?.data?.[0];
1372
- if (excludedIds.includes(hubspotObjectTypeId)) {
1373
- defaultPipelineId = defaultPipeline?.pipelineId || "";
1283
+ async updatePrependEmail(response) {
1284
+ const responseData = { ...response };
1285
+ const state = emailStore.getState();
1286
+ const prependEmails = state.prependEmails || [];
1287
+ const email = response.data || null;
1288
+ const storedAttachments = uploaderStore.getState().attachments;
1289
+ const emails = prependEmails.map(
1290
+ (item) => item?.hs_object_id === email?.hs_object_id?.value ? {
1291
+ ...item,
1292
+ ...Object.fromEntries(
1293
+ Object.entries(email).map(([key, value]) => {
1294
+ if (key === "hs_attachment_ids") {
1295
+ return [key, resolveAttachmentsFromIds(value, storedAttachments)];
1296
+ }
1297
+ return [key, value?.value ?? value];
1298
+ })
1299
+ )
1300
+ } : item
1301
+ );
1302
+ emailStore.setState({
1303
+ prependEmails: emails
1304
+ });
1305
+ if (responseData?.data?.hs_attachment_ids != null) {
1306
+ const emailObjectId = email?.hs_object_id?.value;
1307
+ const rows = state.emails?.data?.results?.rows ?? [];
1308
+ const matchingRow = rows.find((row) => String(row.hs_object_id) === String(emailObjectId));
1309
+ const originalPrependItem = emails.find((item) => String(item?.hs_object_id) === String(emailObjectId));
1310
+ const existingAttachments = matchingRow?.hs_attachment_ids ?? originalPrependItem?.hs_attachment_ids ?? [];
1311
+ const newAttachments = resolveAttachmentsFromIds(responseData.data.hs_attachment_ids, storedAttachments);
1312
+ const mergedAttachments = [
1313
+ ...existingAttachments,
1314
+ ...newAttachments.filter((attachment) => !existingAttachments.some((existing) => String(existing.id) === String(attachment.id)))
1315
+ ];
1316
+ const stateUpdates = {};
1317
+ if (matchingRow && state.emails?.data?.results) {
1318
+ stateUpdates.emails = {
1319
+ ...state.emails,
1320
+ data: {
1321
+ ...state.emails.data,
1322
+ results: {
1323
+ ...state.emails.data.results,
1324
+ rows: rows.map(
1325
+ (row) => String(row.hs_object_id) === String(emailObjectId) ? { ...row, hs_attachment_ids: mergedAttachments } : row
1326
+ )
1327
+ }
1328
+ }
1329
+ };
1330
+ }
1331
+ if (originalPrependItem) {
1332
+ stateUpdates.prependEmails = emails.map(
1333
+ (item) => String(item?.hs_object_id) === String(emailObjectId) ? { ...item, hs_attachment_ids: mergedAttachments } : item
1334
+ );
1335
+ }
1336
+ if (Object.keys(stateUpdates).length > 0) {
1337
+ emailStore.setState(stateUpdates);
1338
+ }
1339
+ responseData.data.hs_attachment_ids = mergedAttachments;
1374
1340
  }
1375
- if (params && params?.filterPropertyName === "hs_pipeline" && params?.filterValue) {
1376
- mFilterValue = params.filterValue;
1377
- } else if (view === "BOARD" && !selectedPipeline) {
1378
- mFilterValue = defaultPipelineId;
1379
- updateLink2({ fV: defaultPipelineId });
1380
- } else if (!excludedIds.includes(hubspotObjectTypeId)) {
1381
- mFilterValue = selectedPipeline || null;
1382
- } else {
1383
- mFilterValue = data.data.length === 1 ? defaultPipelineId : selectedPipeline;
1341
+ return responseData;
1342
+ }
1343
+ };
1344
+
1345
+ // src/main/state/crm/use-user.ts
1346
+ var userStore = createStore({
1347
+ profile: getProfile() ?? null
1348
+ });
1349
+ var actions6 = {
1350
+ setProfile(response) {
1351
+ const data = response?.data ?? null;
1352
+ userStore.setState({
1353
+ profile: data
1354
+ });
1355
+ if (data != null && typeof data === "object") {
1356
+ setProfileDetails(data);
1384
1357
  }
1385
- tableUiStore.setState({ selectedPipeline: mFilterValue });
1386
- return mFilterValue;
1387
1358
  }
1388
1359
  };
1389
1360
 
@@ -1394,7 +1365,9 @@ function createLoadingTreeNode() {
1394
1365
  id: LOADING_TREE_NODE_ID,
1395
1366
  name: "loading",
1396
1367
  type: "loading",
1397
- child: []
1368
+ child: [],
1369
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1370
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
1398
1371
  };
1399
1372
  }
1400
1373
  function isLoadingTreeNode(node) {
@@ -1617,6 +1590,6 @@ var resetAllStore = () => {
1617
1590
  actions7.clearFiles();
1618
1591
  };
1619
1592
 
1620
- export { actions, actions2, actions3, actions4, actions5, actions7 as actions6, actions6 as actions7, actions8, breadcrumbStage, configureLogger, createStore, decodeToBase64, emailStore, fileStore, generatePath, generateUrl, getParam, getParamDetails, getPath, getRouteDetails, getRouteMenu, isHttpTracingEnabled, isMessingParent, isMessingParentLastItem, logger, noteStore, resetAllStore, sanitizeAxiosErrorData, syncStore, tableStore, tableUiActions, tableUiStore, ticketHubspotObjectTypeId, updateLink, uploaderStore, userStore };
1621
- //# sourceMappingURL=chunk-ZEJGWZK3.js.map
1622
- //# sourceMappingURL=chunk-ZEJGWZK3.js.map
1593
+ export { actions, actions2, actions3, actions4, actions5, actions6, actions7, actions8, breadcrumbStage, createStore, decodeToBase64, emailStore, fileStore, formStore, generatePath, generateUrl, getParam, getParamDetails, getPath, getRouteDetails, getRouteMenu, isMessingParent, isMessingParentLastItem, noteStore, resetAllStore, syncStore, tableStore, tableUiActions, tableUiStore, ticketHubspotObjectTypeId, updateLink, uploaderStore, userStore };
1594
+ //# sourceMappingURL=chunk-PFOSN7EB.js.map
1595
+ //# sourceMappingURL=chunk-PFOSN7EB.js.map