woodsportal-client-sdk 1.1.5-dev.0 → 4.0.0-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 (55) hide show
  1. package/CHANGELOG.md +109 -0
  2. package/README.md +171 -77
  3. package/dist/adapters/angular/index.d.ts +68 -5
  4. package/dist/adapters/angular/index.js +8 -7
  5. package/dist/adapters/angular/index.js.map +1 -1
  6. package/dist/adapters/react/index.d.ts +68 -5
  7. package/dist/adapters/react/index.js +7 -6
  8. package/dist/adapters/react/index.js.map +1 -1
  9. package/dist/adapters/vue/index.d.ts +68 -5
  10. package/dist/adapters/vue/index.js +8 -7
  11. package/dist/adapters/vue/index.js.map +1 -1
  12. package/dist/auth-utils-VT7HSLMA.js +3 -0
  13. package/dist/{auth-utils-A4WPJMPK.js.map → auth-utils-VT7HSLMA.js.map} +1 -1
  14. package/dist/authentication-BfYhAeMs.d.ts +463 -0
  15. package/dist/cache-purge-G5WkHckd.d.ts +236 -0
  16. package/dist/chunk-3FUHGFAQ.js +167 -0
  17. package/dist/chunk-3FUHGFAQ.js.map +1 -0
  18. package/dist/chunk-4CEUGRRD.js +2034 -0
  19. package/dist/chunk-4CEUGRRD.js.map +1 -0
  20. package/dist/chunk-4CTHZLKL.js +20 -0
  21. package/dist/chunk-4CTHZLKL.js.map +1 -0
  22. package/dist/chunk-5TLHHOP5.js +1424 -0
  23. package/dist/chunk-5TLHHOP5.js.map +1 -0
  24. package/dist/chunk-7KE6XWM5.js +95 -0
  25. package/dist/chunk-7KE6XWM5.js.map +1 -0
  26. package/dist/{chunk-Y5MRAAGK.js → chunk-AYTO6ND7.js} +3 -3
  27. package/dist/chunk-AYTO6ND7.js.map +1 -0
  28. package/dist/chunk-DZKNBN72.js +399 -0
  29. package/dist/chunk-DZKNBN72.js.map +1 -0
  30. package/dist/chunk-F7B4FHUQ.js +504 -0
  31. package/dist/chunk-F7B4FHUQ.js.map +1 -0
  32. package/dist/entries/auth.d.ts +68 -0
  33. package/dist/entries/auth.js +13 -0
  34. package/dist/entries/auth.js.map +1 -0
  35. package/dist/entries/crm.d.ts +218 -0
  36. package/dist/entries/crm.js +24 -0
  37. package/dist/entries/crm.js.map +1 -0
  38. package/dist/index-CCwMopD8.d.ts +38 -0
  39. package/dist/index.d.ts +415 -406
  40. package/dist/index.js +23 -1720
  41. package/dist/index.js.map +1 -1
  42. package/dist/use-sync-DpazhM4d.d.ts +60 -0
  43. package/dist/use-uploader-2F1zc7Cl.d.ts +23 -0
  44. package/package.json +53 -8
  45. package/dist/auth-utils-A4WPJMPK.js +0 -4
  46. package/dist/chunk-J7MDPY5P.js +0 -54
  47. package/dist/chunk-J7MDPY5P.js.map +0 -1
  48. package/dist/chunk-NB7AINV4.js +0 -35
  49. package/dist/chunk-NB7AINV4.js.map +0 -1
  50. package/dist/chunk-RDCT25UV.js +0 -1066
  51. package/dist/chunk-RDCT25UV.js.map +0 -1
  52. package/dist/chunk-Y5MRAAGK.js.map +0 -1
  53. package/dist/chunk-YLZA5S7A.js +0 -102
  54. package/dist/chunk-YLZA5S7A.js.map +0 -1
  55. package/dist/use-sync-LbURBOs_.d.ts +0 -29
@@ -0,0 +1,1424 @@
1
+ import { getProfile, setProfileDetails, getCookie } from './chunk-3FUHGFAQ.js';
2
+ import axios from 'axios';
3
+ import pako from 'pako';
4
+ import { Base64 } from 'js-base64';
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
+ // src/main/state/crm/store.ts
160
+ function createStore(initialState) {
161
+ let state = initialState;
162
+ const listeners = /* @__PURE__ */ new Set();
163
+ return {
164
+ getState() {
165
+ return state;
166
+ },
167
+ setState(partial) {
168
+ state = {
169
+ ...state,
170
+ ...partial
171
+ };
172
+ listeners.forEach((listener) => listener(state));
173
+ },
174
+ subscribe(listener) {
175
+ listeners.add(listener);
176
+ return () => listeners.delete(listener);
177
+ }
178
+ };
179
+ }
180
+
181
+ // src/main/state/crm/table-ui.ts
182
+ var tableUiStore = createStore({
183
+ tableUniqueId: null,
184
+ gridData: [],
185
+ sort: "-hs_createdate",
186
+ limit: 10,
187
+ after: "",
188
+ page: 1,
189
+ nextPage: 1,
190
+ stageId: "",
191
+ totalItems: 1,
192
+ numOfPages: 1,
193
+ currentPage: 1,
194
+ search: "",
195
+ filterPropertyName: "hs_pipeline",
196
+ filterOperator: "eq",
197
+ filterValue: "",
198
+ isPrimaryCompany: null,
199
+ view: null,
200
+ selectedPipeline: "",
201
+ tableParam: {},
202
+ tableDefPermissions: {}
203
+ });
204
+
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
+ }
220
+ };
221
+
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
+ });
259
+ }
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
+ }
303
+ }
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
+ }
493
+ };
494
+
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 = prependNotes.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 = prependNotes.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
+ }
669
+ };
670
+
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 = prependEmails.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
+ };
797
+ }
798
+ if (originalPrependItem) {
799
+ stateUpdates.prependEmails = prependEmails.map(
800
+ (item) => String(item?.hs_object_id) === String(emailObjectId) ? { ...item, hs_attachment_ids: mergedAttachments } : item
801
+ );
802
+ }
803
+ if (Object.keys(stateUpdates).length > 0) {
804
+ emailStore.setState(stateUpdates);
805
+ }
806
+ responseData.data.hs_attachment_ids = mergedAttachments;
807
+ }
808
+ return responseData;
809
+ }
810
+ };
811
+
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);
823
+ }
824
+ };
825
+
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
+ }
841
+ }
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
+ }
852
+ }
853
+
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
+ );
867
+ }
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";
887
+ }
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}`;
897
+ }
898
+ return url;
899
+ };
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}`
911
+ };
912
+ } else if (index === 1) {
913
+ if (breadcrumb?.isHome) {
914
+ return {
915
+ name: breadcrumb?.n,
916
+ path: `/association/${breadcrumb?.o_t_id}?b=${bc}`
917
+ };
918
+ }
919
+ return {
920
+ name: breadcrumb?.n,
921
+ path: `/${breadcrumb?.o_r_id}/${breadcrumb?.o_t_id}/${breadcrumb?.o_r_id}?b=${bc}`
922
+ };
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 {
930
+ return {
931
+ name: breadcrumb?.n,
932
+ path: `/association/${breadcrumb?.o_t_id}?b=${bc}`
933
+ };
934
+ }
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"
961
+ };
962
+
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 };
974
+ };
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);
980
+ }
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;
990
+ }
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
+ parentObjectTypeId = lastItem?.o_t_id || "";
996
+ parentObjectRecordId = lastItem?.o_r_id || "";
997
+ } else {
998
+ if (breadcrumbs.length > 2) {
999
+ mediatorObjectTypeId = breadcrumbs[1]?.o_t_id || "";
1000
+ mediatorObjectRecordId = breadcrumbs[1]?.o_r_id || "";
1001
+ }
1002
+ if (!lastItem?.o_r_id && breadcrumbs.length > 2) {
1003
+ parentObjectTypeId = lastItem2?.o_t_id || "";
1004
+ parentObjectRecordId = lastItem2?.o_r_id || "";
1005
+ }
1006
+ if (lastItem?.o_r_id && breadcrumbs.length > 2) {
1007
+ parentObjectTypeId = lastItem3?.o_t_id || "";
1008
+ parentObjectRecordId = lastItem3?.o_r_id || "";
1009
+ }
1010
+ if (lastItem2?.o_t_id === "0-5" && !parentObjectTypeId && !parentObjectRecordId) {
1011
+ parentObjectTypeId = lastItem2?.o_t_id || "";
1012
+ parentObjectRecordId = lastItem2?.o_r_id || "";
1013
+ }
1014
+ }
1015
+ }
1016
+ const paramsObject = {};
1017
+ if (breadcrumbs[0]?.prm?.isPC || breadcrumbs[1]?.prm?.isPC || lastItem?.prm?.isPC) {
1018
+ paramsObject["isPrimaryCompany"] = true;
1019
+ }
1020
+ if (parentObjectTypeId && parentObjectRecordId) {
1021
+ paramsObject["parentObjectTypeId"] = parentObjectTypeId;
1022
+ paramsObject["parentObjectRecordId"] = parentObjectRecordId;
1023
+ }
1024
+ if (mediatorObjectTypeId && mediatorObjectRecordId) {
1025
+ paramsObject["mediatorObjectTypeId"] = mediatorObjectTypeId;
1026
+ paramsObject["mediatorObjectRecordId"] = mediatorObjectRecordId;
1027
+ }
1028
+ const mappedLastItemParam = Object.fromEntries(
1029
+ Object.entries(lastItem?.prm || {}).map(([key, value]) => [
1030
+ keyMap[key] || key,
1031
+ // use mapped name if exists, else keep original
1032
+ value
1033
+ ])
1034
+ );
1035
+ let queryString = null;
1036
+ if (props?.type === "association") {
1037
+ queryString = new URLSearchParams({ ...paramsObject, ...{ cache: false } }).toString();
1038
+ } else {
1039
+ queryString = new URLSearchParams({ ...paramsObject, ...mappedLastItemParam }).toString();
1040
+ }
1041
+ const params = queryString ? `?${queryString}` : "";
1042
+ const totalParentLength = getTotalParentLength(breadcrumbs);
1043
+ let parentAccessLabel = false;
1044
+ if (breadcrumbs[0]?.prm?.isPC && totalParentLength > 2 || // company object
1045
+ !breadcrumbs[0]?.prm?.isPC && totalParentLength > 3 || // normal object
1046
+ breadcrumbs[0]?.prm?.isPC && totalParentLength > 1 && props?.type === "ticket" || // company ticket
1047
+ !breadcrumbs[0]?.prm?.isPC && totalParentLength > 2 && props?.type === "ticket") {
1048
+ parentAccessLabel = true;
1049
+ }
1050
+ return {
1051
+ breadcrumbs,
1052
+ // paramsObject: Object.keys(mParamsObject).length === 0 ? null : mParamsObject,
1053
+ paramsObject,
1054
+ params,
1055
+ parentAccessLabel
1056
+ };
1057
+ };
1058
+
1059
+ // src/main/core/utils/url.ts
1060
+ var ticketHubspotObjectTypeId = () => {
1061
+ const paramDetails = getParamDetails();
1062
+ if (
1063
+ // this hubspotObjectTypeId only for main contact ticket object type
1064
+ paramDetails?.breadcrumbs?.length === 2 && paramDetails?.breadcrumbs[0]?.pt === "/0-5"
1065
+ ) {
1066
+ return "0-1";
1067
+ }
1068
+ if (
1069
+ // this hubspotObjectTypeId only for main company ticket object type
1070
+ paramDetails?.breadcrumbs?.length === 2 && paramDetails?.breadcrumbs[0]?.pt === "/0-5-c"
1071
+ ) {
1072
+ return "0-2";
1073
+ }
1074
+ return "";
1075
+ };
1076
+
1077
+ // src/main/core/utils/param.ts
1078
+ function getParam(paramName) {
1079
+ if (typeof globalThis === "undefined" || !globalThis.location) return null;
1080
+ const hash = globalThis.location.hash || "";
1081
+ if (!hash.startsWith("#/")) return null;
1082
+ const hashWithoutHash = hash.startsWith("#") ? hash.substring(1) : hash;
1083
+ const queryString = hashWithoutHash.split("?")[1];
1084
+ if (!queryString) return null;
1085
+ const params = new URLSearchParams(queryString);
1086
+ return params.get(paramName);
1087
+ }
1088
+ function getPath() {
1089
+ if (typeof globalThis === "undefined" || !globalThis.location) return null;
1090
+ const hash = globalThis.location.hash || "";
1091
+ if (!hash.startsWith("#/")) return null;
1092
+ return hash.slice(1).split("?")[0];
1093
+ }
1094
+
1095
+ // src/main/features/navigation/url.ts
1096
+ var updateLink = () => {
1097
+ const updateLink2 = async (props, displayName = "prm") => {
1098
+ const search = getParam("b");
1099
+ const pathname = getPath();
1100
+ let breadcrumbs = decodeToBase64(search) || [];
1101
+ if (breadcrumbs.length < 1) {
1102
+ const routeMenu = getRouteMenu(pathname);
1103
+ breadcrumbs = [
1104
+ {
1105
+ n: routeMenu?.title,
1106
+ pt: routeMenu?.path
1107
+ }
1108
+ ];
1109
+ }
1110
+ const lastBreadcrumb = breadcrumbs[breadcrumbs.length - 1];
1111
+ if (displayName) {
1112
+ const ex = await getDeep(lastBreadcrumb, displayName) || {};
1113
+ await setDeep(lastBreadcrumb, displayName, {
1114
+ ...ex,
1115
+ ...props
1116
+ });
1117
+ } else {
1118
+ await Object.assign(lastBreadcrumb, props);
1119
+ }
1120
+ const newBase64 = convertToBase64(breadcrumbs);
1121
+ updateBParam(newBase64);
1122
+ };
1123
+ function setDeep(obj, path, value) {
1124
+ const keys = path.split(".");
1125
+ let curr = obj;
1126
+ for (let i = 0; i < keys.length - 1; i++) {
1127
+ if (!curr[keys[i]] || typeof curr[keys[i]] !== "object") {
1128
+ curr[keys[i]] = {};
1129
+ }
1130
+ curr = curr[keys[i]];
1131
+ }
1132
+ curr[keys[keys.length - 1]] = value;
1133
+ return curr;
1134
+ }
1135
+ function getDeep(obj, path) {
1136
+ return path.split(".").reduce((acc, key) => acc?.[key], obj);
1137
+ }
1138
+ const getLinkParams = (displayName = "prm") => {
1139
+ const search = getParam("b");
1140
+ const breadcrumbs = decodeToBase64(search) || [];
1141
+ if (breadcrumbs.length < 1) return null;
1142
+ const lastItem = breadcrumbs[breadcrumbs.length - 1];
1143
+ const getDeep2 = (obj, path) => {
1144
+ return path.split(".").reduce((acc, key) => acc?.[key], obj);
1145
+ };
1146
+ const expandKeys = (obj) => {
1147
+ return Object.fromEntries(
1148
+ Object.entries(obj).map(([key, value]) => [
1149
+ keyMap[key] || key,
1150
+ // map if exists, else keep original
1151
+ value
1152
+ ])
1153
+ );
1154
+ };
1155
+ const nestedValue = displayName ? getDeep2(lastItem, displayName) : null;
1156
+ const output = nestedValue ? expandKeys(nestedValue) : null;
1157
+ return output;
1158
+ };
1159
+ const filterParams = (displayName = "prm") => {
1160
+ const search = getParam("b");
1161
+ const breadcrumbs = decodeToBase64(search) || [];
1162
+ if (breadcrumbs.length < 1) return null;
1163
+ const lastItem = breadcrumbs[breadcrumbs.length - 1];
1164
+ const getDeep2 = (obj, path) => {
1165
+ return path.split(".").reduce((acc, key) => acc?.[key], obj);
1166
+ };
1167
+ const expandKeys = (obj) => {
1168
+ return Object.fromEntries(
1169
+ Object.entries(obj).map(([key, value]) => [
1170
+ keyMap[key] || key,
1171
+ // map if exists, else keep original
1172
+ value
1173
+ ])
1174
+ );
1175
+ };
1176
+ const nestedValue = displayName ? getDeep2(lastItem, displayName) : null;
1177
+ const output = nestedValue ? expandKeys(nestedValue) : expandKeys(lastItem);
1178
+ return output;
1179
+ };
1180
+ return { updateLink: updateLink2, getLinkParams, filterParams };
1181
+ };
1182
+ var updateBParam = (newValue) => {
1183
+ if (typeof globalThis === "undefined" || !globalThis.location) return;
1184
+ const hash = globalThis.location.hash || "";
1185
+ if (!hash.startsWith("#/")) return;
1186
+ const withoutHash = hash.slice(2);
1187
+ const [path, queryString] = withoutHash.split("?");
1188
+ const params = new URLSearchParams(queryString || "");
1189
+ params.set("b", newValue);
1190
+ const newHash = `#/${path}?${params.toString()}`;
1191
+ if (typeof globalThis !== "undefined" && globalThis.history && globalThis.history.replaceState) {
1192
+ globalThis.history.replaceState(null, "", newHash);
1193
+ }
1194
+ };
1195
+
1196
+ // src/main/state/crm/table-ui-actions.ts
1197
+ var pageLimit = 10;
1198
+ var boardPaginationDefaults = {
1199
+ stageId: "",
1200
+ nextPage: 1
1201
+ };
1202
+ var tableUiActions = {
1203
+ setTableUniqueId(v) {
1204
+ tableUiStore.setState({ tableUniqueId: v });
1205
+ },
1206
+ setSort(v) {
1207
+ tableUiStore.setState({ sort: v });
1208
+ },
1209
+ setLimit(v) {
1210
+ tableUiStore.setState({ limit: v });
1211
+ },
1212
+ setAfter(v) {
1213
+ tableUiStore.setState({ after: v });
1214
+ },
1215
+ setPage(v) {
1216
+ tableUiStore.setState({ page: v });
1217
+ },
1218
+ setNextPage(v) {
1219
+ tableUiStore.setState({ nextPage: v });
1220
+ },
1221
+ setStageId(v) {
1222
+ tableUiStore.setState({ stageId: v });
1223
+ },
1224
+ setTotalItems(v) {
1225
+ tableUiStore.setState({ totalItems: v });
1226
+ },
1227
+ setNumOfPages(v) {
1228
+ tableUiStore.setState({ numOfPages: v });
1229
+ },
1230
+ setCurrentPage(v) {
1231
+ tableUiStore.setState({ currentPage: v });
1232
+ },
1233
+ setSearch(v) {
1234
+ tableUiStore.setState({ search: v });
1235
+ },
1236
+ setFilterPropertyName(v) {
1237
+ tableUiStore.setState({ filterPropertyName: v });
1238
+ },
1239
+ setFilterOperator(v) {
1240
+ tableUiStore.setState({ filterOperator: v });
1241
+ },
1242
+ setFilterValue(v) {
1243
+ tableUiStore.setState({ filterValue: v });
1244
+ },
1245
+ setIsPrimaryCompany(v) {
1246
+ tableUiStore.setState({ isPrimaryCompany: v });
1247
+ },
1248
+ setTableFilterData(v) {
1249
+ tableUiStore.setState({ tableParam: v });
1250
+ },
1251
+ setTableDefPermissions(v) {
1252
+ tableUiStore.setState({ tableDefPermissions: v });
1253
+ },
1254
+ setView(mView) {
1255
+ tableUiStore.setState({
1256
+ page: getAuthSubscriptionType() === "FREE" ? "" : 1,
1257
+ view: mView,
1258
+ ...boardPaginationDefaults
1259
+ });
1260
+ },
1261
+ changePipeline(mView) {
1262
+ tableUiStore.setState({
1263
+ page: getAuthSubscriptionType() === "FREE" ? "" : 1,
1264
+ selectedPipeline: mView || ""
1265
+ });
1266
+ },
1267
+ setSelectedPipeline(pipelines, pipeLineId) {
1268
+ let filterValue = "";
1269
+ if (pipeLineId) {
1270
+ const pipelineSingle = pipelines.find((pipeline) => pipeline.pipelineId === pipeLineId);
1271
+ filterValue = pipelineSingle?.pipelineId || "";
1272
+ }
1273
+ tableUiStore.setState({
1274
+ filterPropertyName: "hs_pipeline",
1275
+ filterOperator: "eq",
1276
+ filterValue,
1277
+ selectedPipeline: filterValue
1278
+ });
1279
+ },
1280
+ resetTableParam() {
1281
+ tableUiStore.setState({
1282
+ sort: "-hs_createdate",
1283
+ limit: pageLimit,
1284
+ after: "",
1285
+ page: getAuthSubscriptionType() === "FREE" ? "" : 1,
1286
+ totalItems: 1,
1287
+ numOfPages: 1,
1288
+ currentPage: 1,
1289
+ search: "",
1290
+ filterPropertyName: "hs_pipeline",
1291
+ filterOperator: "eq",
1292
+ filterValue: "",
1293
+ isPrimaryCompany: null,
1294
+ selectedPipeline: ""
1295
+ });
1296
+ },
1297
+ getTableParam(companyAsMediator, currentPageOverride) {
1298
+ const state = tableUiStore.getState();
1299
+ const baseParams = {
1300
+ sort: state.sort,
1301
+ search: state.search,
1302
+ filterPropertyName: state.filterPropertyName,
1303
+ filterOperator: state.filterOperator,
1304
+ filterValue: state.selectedPipeline,
1305
+ cache: true,
1306
+ isPrimaryCompany: companyAsMediator || false,
1307
+ view: state.view
1308
+ };
1309
+ if (getAuthSubscriptionType() === "FREE") {
1310
+ return {
1311
+ ...baseParams,
1312
+ after: state.page
1313
+ };
1314
+ }
1315
+ return {
1316
+ ...baseParams,
1317
+ limit: state.limit,
1318
+ page: currentPageOverride ?? state.page,
1319
+ ...state.after ? { after: state.after } : {}
1320
+ };
1321
+ },
1322
+ buildListTableParams(options) {
1323
+ return tableUiActions.getTableParam(options?.companyAsMediator, options?.currentPageOverride);
1324
+ },
1325
+ async setGridData(type, deals) {
1326
+ if (type === "reset") {
1327
+ tableUiStore.setState({ gridData: [] });
1328
+ return [];
1329
+ }
1330
+ if (type === "directly") {
1331
+ tableUiStore.setState({ gridData: deals });
1332
+ return deals;
1333
+ }
1334
+ const finalData = deals.map((deal) => {
1335
+ const cards = deal?.data?.results?.rows?.map((row) => ({
1336
+ id: row?.hs_object_id,
1337
+ ...row,
1338
+ hubspotObjectTypeId: type === "deals" ? "0-3" : "0-5"
1339
+ })) || [];
1340
+ return {
1341
+ id: deal.id,
1342
+ name: deal.label,
1343
+ count: deal?.data?.total,
1344
+ ...deal,
1345
+ cards
1346
+ };
1347
+ });
1348
+ tableUiStore.setState({ gridData: finalData });
1349
+ return finalData;
1350
+ },
1351
+ setDefaultPipeline(data, hubspotObjectTypeId) {
1352
+ if (!data) {
1353
+ tableUiStore.setState({ selectedPipeline: "" });
1354
+ return "";
1355
+ }
1356
+ const { updateLink: updateLink2, filterParams } = updateLink();
1357
+ const params = filterParams();
1358
+ const excludedIds = ["0-1", "0-2", "0-3", "0-4", "0-5", "home"];
1359
+ const state = tableUiStore.getState();
1360
+ const view = state.view;
1361
+ const selectedPipeline = state.selectedPipeline;
1362
+ let defaultPipelineId = "";
1363
+ let mFilterValue = "";
1364
+ const defaultPipeline = data?.data?.[0];
1365
+ if (excludedIds.includes(hubspotObjectTypeId)) {
1366
+ defaultPipelineId = defaultPipeline?.pipelineId || "";
1367
+ }
1368
+ if (params && params?.filterPropertyName === "hs_pipeline" && params?.filterValue) {
1369
+ mFilterValue = params.filterValue;
1370
+ } else if (view === "BOARD" && !selectedPipeline) {
1371
+ mFilterValue = defaultPipelineId;
1372
+ updateLink2({ fV: defaultPipelineId });
1373
+ } else if (!excludedIds.includes(hubspotObjectTypeId)) {
1374
+ mFilterValue = selectedPipeline || null;
1375
+ } else {
1376
+ mFilterValue = data.data.length === 1 ? defaultPipelineId : selectedPipeline;
1377
+ }
1378
+ tableUiStore.setState({ selectedPipeline: mFilterValue });
1379
+ return mFilterValue;
1380
+ }
1381
+ };
1382
+
1383
+ // src/main/state/crm/use-sync.ts
1384
+ var syncStore = createStore({
1385
+ apiSync: false,
1386
+ sync: false,
1387
+ isSyncLoading: false,
1388
+ isSyncDisable: false
1389
+ });
1390
+ var actions7 = {
1391
+ setIsSyncLoading(status) {
1392
+ syncStore.setState({
1393
+ isSyncLoading: status,
1394
+ sync: status
1395
+ });
1396
+ },
1397
+ setSync(status) {
1398
+ resetAllStore();
1399
+ syncStore.setState({
1400
+ isSyncLoading: status,
1401
+ sync: status
1402
+ });
1403
+ },
1404
+ setApiSync(status) {
1405
+ syncStore.setState({
1406
+ isSyncLoading: status,
1407
+ apiSync: status
1408
+ });
1409
+ },
1410
+ setSyncDisable(status) {
1411
+ syncStore.setState({
1412
+ isSyncDisable: status
1413
+ });
1414
+ }
1415
+ };
1416
+ var resetAllStore = () => {
1417
+ actions2.clearTablePrependData();
1418
+ actions4.clearPrependNotes();
1419
+ actions5.clearPrependEmails();
1420
+ };
1421
+
1422
+ export { actions, actions2, actions3, actions4, actions5, actions6, actions7, breadcrumbStage, configureLogger, createStore, decodeToBase64, emailStore, generatePath, generateUrl, getParam, getParamDetails, getPath, getRouteDetails, getRouteMenu, isHttpTracingEnabled, isMessingParent, isMessingParentLastItem, logger, noteStore, resetAllStore, sanitizeAxiosErrorData, syncStore, tableStore, tableUiActions, tableUiStore, ticketHubspotObjectTypeId, updateLink, uploaderStore, userStore };
1423
+ //# sourceMappingURL=chunk-5TLHHOP5.js.map
1424
+ //# sourceMappingURL=chunk-5TLHHOP5.js.map