@elevasis/ui 2.33.2 → 2.35.0

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 (116) hide show
  1. package/dist/api/index.d.ts +9 -2
  2. package/dist/api/index.js +3 -3
  3. package/dist/app/index.css +452 -0
  4. package/dist/app/index.d.ts +1255 -8
  5. package/dist/app/index.js +151 -13
  6. package/dist/charts/index.js +3 -6
  7. package/dist/chunk-26HFM4MH.js +41449 -0
  8. package/dist/{chunk-52K5RFDH.js → chunk-4U3XAWCN.js} +1328 -2492
  9. package/dist/{chunk-ND5TDV2J.js → chunk-57OZ3AEG.js} +1 -1
  10. package/dist/{chunk-E4WQGJNS.js → chunk-7FPLLSHN.js} +14 -1
  11. package/dist/{chunk-RQA2EVN3.js → chunk-AKW7KISS.js} +39 -3
  12. package/dist/chunk-AUDNF2Q7.js +2050 -0
  13. package/dist/{chunk-TYRUKGGD.js → chunk-GX6XBRRF.js} +1 -2
  14. package/dist/{chunk-V6SZ4ECN.js → chunk-LUYVRATI.js} +257 -6
  15. package/dist/{chunk-X4WBGKJQ.js → chunk-R3VCBZDC.js} +50 -3
  16. package/dist/chunk-SIQ3P4OR.js +1764 -0
  17. package/dist/{chunk-Z2K2EAPL.js → chunk-VDOOGGBA.js} +5 -6
  18. package/dist/{chunk-3FV6HBXS.js → chunk-WF7CONXF.js} +23 -23
  19. package/dist/chunk-YYX7OPZQ.js +25 -0
  20. package/dist/components/index.d.ts +69 -92
  21. package/dist/components/index.js +20 -3216
  22. package/dist/components/navigation/index.js +25 -7
  23. package/dist/execution/index.d.ts +9 -9
  24. package/dist/execution/index.js +1 -2
  25. package/dist/features/auth/index.js +23 -2
  26. package/dist/features/clients/index.js +20 -31
  27. package/dist/features/crm/index.js +20 -35
  28. package/dist/features/dashboard/index.d.ts +68 -91
  29. package/dist/features/dashboard/index.js +20 -33
  30. package/dist/features/delivery/index.js +20 -35
  31. package/dist/features/knowledge/index.js +25 -11
  32. package/dist/features/lead-gen/index.d.ts +9 -9
  33. package/dist/features/lead-gen/index.js +20 -36
  34. package/dist/features/monitoring/index.js +20 -35
  35. package/dist/features/monitoring/requests/index.js +20 -30
  36. package/dist/features/operations/index.d.ts +197 -188
  37. package/dist/features/operations/index.js +18 -42
  38. package/dist/features/seo/index.js +3 -4
  39. package/dist/features/settings/index.js +20 -32
  40. package/dist/graph/index.js +1 -1
  41. package/dist/hooks/delivery/index.js +30 -2
  42. package/dist/hooks/index.d.ts +105 -112
  43. package/dist/hooks/index.js +20 -26
  44. package/dist/hooks/operations/command-view/utils/transformCommandViewData.d.ts +55 -62
  45. package/dist/hooks/published.d.ts +105 -112
  46. package/dist/hooks/published.js +20 -25
  47. package/dist/index.css +532 -532
  48. package/dist/index.d.ts +10261 -6793
  49. package/dist/index.js +22 -31
  50. package/dist/knowledge/index.d.ts +51 -59
  51. package/dist/knowledge/index.js +40 -211
  52. package/dist/{knowledge-search-index-VMAW7FLR.js → knowledge-search-index-ORIJCEZX.js} +3 -3
  53. package/dist/layout/index.js +4 -10
  54. package/dist/organization/index.js +27 -2
  55. package/dist/provider/index.d.ts +71 -52
  56. package/dist/provider/index.js +20 -20
  57. package/dist/provider/published.d.ts +39 -47
  58. package/dist/provider/published.js +20 -15
  59. package/dist/test-utils/index.d.ts +2 -0
  60. package/dist/test-utils/index.js +16 -4
  61. package/dist/test-utils/setup.js +38 -0
  62. package/dist/theme/index.js +2 -3
  63. package/dist/theme/presets/index.d.ts +28 -3
  64. package/dist/theme/presets/index.js +1 -1
  65. package/dist/typeform/index.js +1 -2049
  66. package/dist/types/index.d.ts +88 -95
  67. package/dist/utils/index.d.ts +46 -69
  68. package/dist/utils/index.js +1 -1
  69. package/dist/zustand/index.d.ts +21 -8
  70. package/dist/zustand/index.js +32 -1
  71. package/package.json +5 -5
  72. package/dist/chunk-2ZZ72TAB.js +0 -2281
  73. package/dist/chunk-32I2RCGC.js +0 -85
  74. package/dist/chunk-3MEXPLWT.js +0 -265
  75. package/dist/chunk-3ZMAGTWF.js +0 -18
  76. package/dist/chunk-44I4LOH6.js +0 -1593
  77. package/dist/chunk-4DYOXEH6.js +0 -951
  78. package/dist/chunk-7M2VOCYN.js +0 -1
  79. package/dist/chunk-A4VDJJCV.js +0 -1864
  80. package/dist/chunk-BZZCNLT6.js +0 -12
  81. package/dist/chunk-CLDCYJQT.js +0 -1
  82. package/dist/chunk-E565XMTQ.js +0 -17
  83. package/dist/chunk-EPTHX4VZ.js +0 -749
  84. package/dist/chunk-GWGQI6V4.js +0 -447
  85. package/dist/chunk-HUJCU55S.js +0 -159
  86. package/dist/chunk-IBWMR4TI.js +0 -469
  87. package/dist/chunk-IIMU5YAJ.js +0 -53
  88. package/dist/chunk-IOXOPMYS.js +0 -145
  89. package/dist/chunk-J2UD7BOH.js +0 -347
  90. package/dist/chunk-JA5ECJJB.js +0 -387
  91. package/dist/chunk-JFL3GRD4.js +0 -39
  92. package/dist/chunk-KW7ZNQD7.js +0 -126
  93. package/dist/chunk-LGKLC5MG.js +0 -44
  94. package/dist/chunk-N55DVMAG.js +0 -14
  95. package/dist/chunk-O56ESZCQ.js +0 -1874
  96. package/dist/chunk-OIBHQH5Q.js +0 -96
  97. package/dist/chunk-PDHTXPSF.js +0 -12
  98. package/dist/chunk-QDFJSUG3.js +0 -13
  99. package/dist/chunk-R2XR4FCV.js +0 -48
  100. package/dist/chunk-R66W5UDG.js +0 -26
  101. package/dist/chunk-RYTEQBAO.js +0 -37
  102. package/dist/chunk-SZHARWKU.js +0 -15
  103. package/dist/chunk-T3J6U77J.js +0 -12056
  104. package/dist/chunk-TBVLQRXT.js +0 -68
  105. package/dist/chunk-TGVAIWIL.js +0 -1778
  106. package/dist/chunk-TKAYX2SP.js +0 -204
  107. package/dist/chunk-TUMSNGTX.js +0 -35
  108. package/dist/chunk-VGU4ZFYZ.js +0 -4752
  109. package/dist/chunk-VNAZTCHA.js +0 -65
  110. package/dist/chunk-VNFR57DF.js +0 -87
  111. package/dist/chunk-WKW6B5ID.js +0 -29
  112. package/dist/chunk-XCYKC6OZ.js +0 -1
  113. package/dist/chunk-XZGSCABI.js +0 -383
  114. package/dist/chunk-ZMK5Z6KE.js +0 -5198
  115. /package/dist/{chunk-2RJMVWFJ.js → chunk-GEFWMU26.js} +0 -0
  116. /package/dist/{chunk-22UVE3RA.js → chunk-HENXLGVD.js} +0 -0
@@ -1,447 +0,0 @@
1
- import { formatOntologyId, DEFAULT_ORGANIZATION_MODEL, CRM_DISCOVERY_NUDGING_STATE, compileOrganizationOntology, CRM_DISCOVERY_REPLIED_STATE, CRM_DISCOVERY_LINK_SENT_STATE, CRM_DISCOVERY_BOOKING_CANCELLED_STATE, CRM_PIPELINE_DEFINITION, LEAD_GEN_STAGE_CATALOG } from './chunk-52K5RFDH.js';
2
- import { ApiClientProvider, useApiClient } from './chunk-ND5TDV2J.js';
3
- import { OrganizationProvider } from './chunk-HUJCU55S.js';
4
- import { getErrorInfo, getErrorTitle, formatErrorMessage } from './chunk-2RJMVWFJ.js';
5
- import { InitializationProvider } from './chunk-533DUEQY.js';
6
- import { useOrganization } from './chunk-DD3CCMCZ.js';
7
- import { ProfileProvider } from './chunk-2Q2JQSQO.js';
8
- import { ElevasisServiceProvider } from './chunk-KJ3QUBNU.js';
9
- import { useAuthContext } from './chunk-BRJ3QZ4E.js';
10
- import { createContext, lazy, useContext, Suspense, useRef } from 'react';
11
- import { jsx } from 'react/jsx-runtime';
12
- import { z } from 'zod';
13
- import { QueryClientProvider, QueryClient } from '@tanstack/react-query';
14
-
15
- var consoleAdapter = {
16
- success(title, message) {
17
- console.log(`[Notification][Success] ${title}: ${message}`);
18
- },
19
- error(title, message) {
20
- console.warn(`[Notification][Error] ${title}: ${message}`);
21
- },
22
- info(title, message) {
23
- console.log(`[Notification][Info] ${title}: ${message}`);
24
- },
25
- warning(title, message) {
26
- console.warn(`[Notification][Warning] ${title}: ${message}`);
27
- },
28
- apiError(error) {
29
- const { message, code, requestId, fields, retryAfter } = getErrorInfo(error);
30
- const title = getErrorTitle(code);
31
- const formatted = formatErrorMessage(message, requestId, fields, retryAfter);
32
- console.warn(`[Notification][API Error] ${title}: ${formatted}`);
33
- }
34
- };
35
- var NotificationContext = createContext(consoleAdapter);
36
- function NotificationProvider({ adapter, children }) {
37
- return /* @__PURE__ */ jsx(NotificationContext.Provider, { value: adapter, children });
38
- }
39
- function useNotificationAdapter() {
40
- return useContext(NotificationContext);
41
- }
42
-
43
- // ../core/src/business/acquisition/ontology-validation.ts
44
- var CRM_PIPELINE_CATALOG_ONTOLOGY_ID = formatOntologyId({
45
- scope: "sales.crm",
46
- kind: "catalog",
47
- localId: "crm.pipeline"
48
- });
49
- var LEAD_GEN_STAGE_CATALOG_ONTOLOGY_ID = formatOntologyId({
50
- scope: "sales.lead-gen",
51
- kind: "catalog",
52
- localId: "lead-gen.stage-catalog"
53
- });
54
- var CRM_DEAL_OBJECT_ONTOLOGY_ID = formatOntologyId({
55
- scope: "sales.crm",
56
- kind: "object",
57
- localId: "crm.deal"
58
- });
59
- function createCrmPipelineCatalog() {
60
- return {
61
- id: CRM_PIPELINE_CATALOG_ONTOLOGY_ID,
62
- label: CRM_PIPELINE_DEFINITION.label,
63
- ownerSystemId: "sales.crm",
64
- kind: "pipeline",
65
- appliesTo: CRM_DEAL_OBJECT_ONTOLOGY_ID,
66
- entries: Object.fromEntries(
67
- CRM_PIPELINE_DEFINITION.stages.map((stage, index) => [
68
- stage.stageKey,
69
- {
70
- key: stage.stageKey,
71
- label: stage.label,
72
- order: (index + 1) * 10,
73
- ...stage.color !== void 0 ? { color: stage.color } : {},
74
- states: stage.states.map((state) => ({ ...state }))
75
- }
76
- ])
77
- ),
78
- legacyPipelineKey: CRM_PIPELINE_DEFINITION.pipelineKey,
79
- legacyEntityKey: CRM_PIPELINE_DEFINITION.entityKey
80
- };
81
- }
82
- function createLeadGenStageCatalog() {
83
- return {
84
- id: LEAD_GEN_STAGE_CATALOG_ONTOLOGY_ID,
85
- label: "Lead Gen Processing Stages",
86
- ownerSystemId: "sales.lead-gen",
87
- kind: "processing-stage-catalog",
88
- entries: Object.fromEntries(
89
- Object.entries(LEAD_GEN_STAGE_CATALOG).map(([key, entry]) => [
90
- key,
91
- {
92
- ...entry
93
- }
94
- ])
95
- ),
96
- legacyCatalogKey: "LEAD_GEN_STAGE_CATALOG"
97
- };
98
- }
99
- function isPlainRecord(value) {
100
- return Boolean(value) && typeof value === "object" && !Array.isArray(value);
101
- }
102
- function mergeBridgeCatalogs(model) {
103
- const baseCatalogTypes = model.ontology?.catalogTypes ?? {};
104
- const bridgeCatalogTypes = {};
105
- if (baseCatalogTypes[CRM_PIPELINE_CATALOG_ONTOLOGY_ID] === void 0) {
106
- bridgeCatalogTypes[CRM_PIPELINE_CATALOG_ONTOLOGY_ID] = createCrmPipelineCatalog();
107
- }
108
- if (baseCatalogTypes[LEAD_GEN_STAGE_CATALOG_ONTOLOGY_ID] === void 0) {
109
- bridgeCatalogTypes[LEAD_GEN_STAGE_CATALOG_ONTOLOGY_ID] = createLeadGenStageCatalog();
110
- }
111
- if (Object.keys(bridgeCatalogTypes).length === 0) return model;
112
- return {
113
- ...model,
114
- ontology: {
115
- ...model.ontology ?? {},
116
- catalogTypes: {
117
- ...baseCatalogTypes,
118
- ...bridgeCatalogTypes
119
- }
120
- }
121
- };
122
- }
123
- function compileBusinessOntologyValidationIndex(model = DEFAULT_ORGANIZATION_MODEL) {
124
- const compilation = compileOrganizationOntology(mergeBridgeCatalogs(model));
125
- if (compilation.diagnostics.length > 0) {
126
- const summary = compilation.diagnostics.map((diagnostic) => diagnostic.message).join("; ");
127
- throw new Error(`Business ontology validation index failed to compile: ${summary}`);
128
- }
129
- const crmPipelineCatalog = compilation.ontology.catalogTypes[CRM_PIPELINE_CATALOG_ONTOLOGY_ID];
130
- const leadGenStageCatalog = compilation.ontology.catalogTypes[LEAD_GEN_STAGE_CATALOG_ONTOLOGY_ID];
131
- if (crmPipelineCatalog === void 0 || leadGenStageCatalog === void 0) {
132
- throw new Error("Business ontology validation index is missing CRM or lead-gen catalog bridge records");
133
- }
134
- return {
135
- ontology: compilation.ontology,
136
- crmPipelineCatalog,
137
- leadGenStageCatalog,
138
- actionTypesByLegacyId: indexActionTypesByLegacyId(compilation.ontology.actionTypes)
139
- };
140
- }
141
- function indexActionTypesByLegacyId(actionTypes) {
142
- const byLegacyId = {};
143
- for (const actionType of Object.values(actionTypes)) {
144
- const legacyActionId = actionType["legacyActionId"];
145
- if (typeof legacyActionId === "string") {
146
- byLegacyId[legacyActionId] = actionType;
147
- }
148
- }
149
- return byLegacyId;
150
- }
151
- var BUSINESS_ONTOLOGY_VALIDATION_INDEX = compileBusinessOntologyValidationIndex();
152
- function getCatalogEntries(catalog) {
153
- return isPlainRecord(catalog.entries) ? catalog.entries : {};
154
- }
155
- function asCrmStageEntry(key, value) {
156
- const record = isPlainRecord(value) ? value : {};
157
- const label = typeof record.label === "string" ? record.label : key;
158
- const order = typeof record.order === "number" ? record.order : 0;
159
- const color = typeof record.color === "string" ? record.color : void 0;
160
- const rawStates = Array.isArray(record.states) ? record.states : [];
161
- const states = rawStates.flatMap((state) => {
162
- if (!isPlainRecord(state) || typeof state.stateKey !== "string") return [];
163
- return [
164
- {
165
- stateKey: state.stateKey,
166
- label: typeof state.label === "string" ? state.label : state.stateKey
167
- }
168
- ];
169
- });
170
- return {
171
- key,
172
- label,
173
- order,
174
- ...color !== void 0 ? { color } : {},
175
- states
176
- };
177
- }
178
- var CRM_STAGE_KEYS_FROM_ONTOLOGY = Object.keys(
179
- getCatalogEntries(BUSINESS_ONTOLOGY_VALIDATION_INDEX.crmPipelineCatalog)
180
- );
181
- Object.values(
182
- getCatalogEntries(BUSINESS_ONTOLOGY_VALIDATION_INDEX.crmPipelineCatalog)
183
- ).flatMap((entry, index) => {
184
- const stageKey = CRM_STAGE_KEYS_FROM_ONTOLOGY[index];
185
- if (stageKey === void 0) return [];
186
- return asCrmStageEntry(stageKey, entry).states.map((state) => state.stateKey);
187
- });
188
- Object.keys(
189
- getCatalogEntries(BUSINESS_ONTOLOGY_VALIDATION_INDEX.leadGenStageCatalog)
190
- );
191
- function getActionMetadata(actionKey) {
192
- const actionType = BUSINESS_ONTOLOGY_VALIDATION_INDEX.actionTypesByLegacyId[actionKey];
193
- if (actionType === void 0) return void 0;
194
- const resourceId = actionType["resourceId"];
195
- return {
196
- id: actionKey,
197
- label: actionType.label ?? actionKey,
198
- ...typeof resourceId === "string" ? { resourceId } : {}
199
- };
200
- }
201
- function getCrmActionMetadata(actionKey) {
202
- const actionType = BUSINESS_ONTOLOGY_VALIDATION_INDEX.actionTypesByLegacyId[actionKey];
203
- return actionType?.ownerSystemId === "sales.crm" ? getActionMetadata(actionKey) : void 0;
204
- }
205
-
206
- // ../core/src/business/acquisition/deal-ownership.ts
207
- var INBOUND_EVENT_TYPES = ["reply_received"];
208
- var OUTBOUND_EVENT_TYPES = [
209
- "reply_sent_to_lead",
210
- "booking_nudge_sent",
211
- "reminder_sent",
212
- "rebook_sent",
213
- "followup_email_sent",
214
- "reply_followup_sent",
215
- "lead_deferred_next_step"
216
- ];
217
- var INBOUND_SET = new Set(INBOUND_EVENT_TYPES);
218
- var OUTBOUND_SET = new Set(OUTBOUND_EVENT_TYPES);
219
- function getDealOwnership(deal) {
220
- if (deal.state_key === "closed_won" || deal.state_key === "closed_lost") {
221
- return null;
222
- }
223
- if (!Array.isArray(deal.activity_log)) return null;
224
- let latestInboundMs = null;
225
- let latestOutboundMs = null;
226
- for (const entry of deal.activity_log) {
227
- if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue;
228
- const record = entry;
229
- const type = typeof record.type === "string" ? record.type : null;
230
- if (!type) continue;
231
- const isInbound = INBOUND_SET.has(type);
232
- const isOutbound = OUTBOUND_SET.has(type);
233
- if (!isInbound && !isOutbound) continue;
234
- const occurredAt = resolveTimestamp(record);
235
- if (occurredAt === null) continue;
236
- if (isInbound && (latestInboundMs === null || occurredAt > latestInboundMs)) {
237
- latestInboundMs = occurredAt;
238
- }
239
- if (isOutbound && (latestOutboundMs === null || occurredAt > latestOutboundMs)) {
240
- latestOutboundMs = occurredAt;
241
- }
242
- }
243
- if (latestInboundMs === null && latestOutboundMs === null) return null;
244
- if (latestOutboundMs !== null && (latestInboundMs === null || latestOutboundMs >= latestInboundMs)) {
245
- return "them";
246
- }
247
- return "us";
248
- }
249
- function resolveTimestamp(record) {
250
- return parseMs(record.timestamp) ?? parseMs(record.occurredAt) ?? parseMs(record.createdAt) ?? parseMs(record.updatedAt) ?? parseMs(record.sentAt) ?? null;
251
- }
252
- function parseMs(value) {
253
- if (value instanceof Date) {
254
- const ms2 = value.getTime();
255
- return Number.isNaN(ms2) ? null : ms2;
256
- }
257
- if (typeof value !== "string") return null;
258
- const ms = new Date(value).getTime();
259
- return Number.isNaN(ms) ? null : ms;
260
- }
261
- var SendReplyActionPayloadSchema = z.object({
262
- replyBody: z.string().trim().min(1).max(1e4)
263
- }).strict();
264
- function crmAction(actionId, runtime) {
265
- const metadata = getCrmActionMetadata(actionId);
266
- if (!metadata?.resourceId) {
267
- throw new Error(`CRM action metadata for "${actionId}" must define resourceId`);
268
- }
269
- return {
270
- key: metadata.id,
271
- label: metadata.label,
272
- workflowId: metadata.resourceId,
273
- ...runtime
274
- };
275
- }
276
- var DEFAULT_CRM_ACTIONS = [
277
- crmAction("move_to_proposal", {
278
- isAvailableFor: (deal) => deal.stage_key === "interested"
279
- }),
280
- crmAction("move_to_closing", {
281
- isAvailableFor: (deal) => deal.stage_key === "proposal"
282
- }),
283
- crmAction("move_to_closed_won", {
284
- isAvailableFor: (deal) => deal.stage_key === "closing"
285
- }),
286
- crmAction("move_to_closed_lost", {
287
- isAvailableFor: (deal) => deal.stage_key === "interested" || deal.stage_key === "proposal" || deal.stage_key === "closing"
288
- }),
289
- crmAction("move_to_nurturing", {
290
- isAvailableFor: (deal) => deal.stage_key === "interested" || deal.stage_key === "proposal" || deal.stage_key === "closing"
291
- }),
292
- crmAction("send_reply", {
293
- isAvailableFor: (deal) => deal.stage_key === "interested" && isOurReplyAction(deal) && (deal.state_key === CRM_DISCOVERY_REPLIED_STATE.stateKey || deal.state_key === CRM_DISCOVERY_LINK_SENT_STATE.stateKey || deal.state_key === CRM_DISCOVERY_NUDGING_STATE.stateKey),
294
- payloadSchema: SendReplyActionPayloadSchema
295
- }),
296
- crmAction("send_link", {
297
- isAvailableFor: (deal) => deal.stage_key === "interested" && deal.state_key === CRM_DISCOVERY_REPLIED_STATE.stateKey
298
- }),
299
- crmAction("send_nudge", {
300
- isAvailableFor: (deal) => deal.stage_key === "interested" && (deal.state_key === CRM_DISCOVERY_LINK_SENT_STATE.stateKey || deal.state_key === CRM_DISCOVERY_NUDGING_STATE.stateKey)
301
- }),
302
- {
303
- key: "mark_no_show",
304
- label: "Mark No-Show",
305
- isAvailableFor: (deal) => deal.stage_key === "interested" && deal.state_key === CRM_DISCOVERY_NUDGING_STATE.stateKey,
306
- // Mirrors the auto-timeout precedent in operations/sales/crm/pipeline/timeout-actions.ts:
307
- // both manual-click and timeout move the deal to closed_lost. The action_taken activity
308
- // event captures operator intent and distinguishes the manual variant from the timed one.
309
- workflowId: "mark_no_show-workflow"
310
- },
311
- crmAction("rebook", {
312
- isAvailableFor: (deal) => deal.stage_key === "interested" && deal.state_key === CRM_DISCOVERY_BOOKING_CANCELLED_STATE.stateKey
313
- })
314
- ];
315
- function deriveActions(deal, actions = DEFAULT_CRM_ACTIONS) {
316
- return actions.filter((a) => a.isAvailableFor(deal)).map(({ key, label, payloadSchema }) => ({ key, label, payloadSchema }));
317
- }
318
- function isOurReplyAction(deal) {
319
- if (Object.prototype.hasOwnProperty.call(deal, "nextAction")) {
320
- return deal.nextAction === "send_reply";
321
- }
322
- return (deal.ownership ?? getDealOwnership(deal)) === "us";
323
- }
324
- var CrmActionsContext = createContext(DEFAULT_CRM_ACTIONS);
325
- function CrmActionsProvider({ actions, children }) {
326
- return /* @__PURE__ */ jsx(CrmActionsContext.Provider, { value: actions, children });
327
- }
328
- function useCrmActions() {
329
- return useContext(CrmActionsContext);
330
- }
331
- var EMPTY_LIST_ACTIONS = Object.freeze([]);
332
- var ListActionsContext = createContext(EMPTY_LIST_ACTIONS);
333
- function ListActionsProvider({
334
- registry = EMPTY_LIST_ACTIONS,
335
- children
336
- }) {
337
- return /* @__PURE__ */ jsx(ListActionsContext.Provider, { value: registry, children });
338
- }
339
- function useListActions() {
340
- return useContext(ListActionsContext);
341
- }
342
- function findListActionByAction(registry, actionKey) {
343
- return registry.find((action) => action.actionKey === actionKey);
344
- }
345
- function getListActionWorkflowId(action) {
346
- return action.workflowId ?? action.resourceId;
347
- }
348
- var LazyCoreAuthKitInner = lazy(() => import('./CoreAuthKitInner-QC62UHTZ.js').then((m) => ({ default: m.CoreAuthKitInner })));
349
- var defaultQueryClient = null;
350
- function getDefaultQueryClient() {
351
- if (!defaultQueryClient) {
352
- defaultQueryClient = new QueryClient({
353
- defaultOptions: { queries: { retry: 1 } }
354
- });
355
- }
356
- return defaultQueryClient;
357
- }
358
- var consoleNotificationAdapter = {
359
- success(title, message) {
360
- console.log(`[Notification][Success] ${title}: ${message}`);
361
- },
362
- error(title, message) {
363
- console.warn(`[Notification][Error] ${title}: ${message}`);
364
- },
365
- info(title, message) {
366
- console.log(`[Notification][Info] ${title}: ${message}`);
367
- },
368
- warning(title, message) {
369
- console.warn(`[Notification][Warning] ${title}: ${message}`);
370
- },
371
- apiError(error) {
372
- console.warn(`[Notification][API Error]`, error);
373
- }
374
- };
375
- function ElevasisCoreProvider({
376
- auth,
377
- queryClient,
378
- apiUrl,
379
- onError,
380
- notifications,
381
- crmActions,
382
- listActions,
383
- children
384
- }) {
385
- if (auth.mode === "apiKey") {
386
- throw new Error(
387
- `ElevasisCoreProvider: auth mode 'apiKey' is not yet implemented. Only 'authkit' mode is supported.`
388
- );
389
- }
390
- const resolvedQueryClient = queryClient ?? getDefaultQueryClient();
391
- const resolvedCrmActions = crmActions ?? DEFAULT_CRM_ACTIONS;
392
- const resolvedListActions = listActions ?? EMPTY_LIST_ACTIONS;
393
- const content = apiUrl ? /* @__PURE__ */ jsx(ServiceStack, { apiUrl, onError, notifications, children }) : children;
394
- const AuthInner = /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(LazyCoreAuthKitInner, { auth, children: content }) });
395
- return /* @__PURE__ */ jsx(QueryClientProvider, { client: resolvedQueryClient, children: /* @__PURE__ */ jsx(CrmActionsProvider, { actions: resolvedCrmActions, children: /* @__PURE__ */ jsx(ListActionsProvider, { registry: resolvedListActions, children: AuthInner }) }) });
396
- }
397
- function ServiceStack({
398
- apiUrl,
399
- onError,
400
- notifications,
401
- children
402
- }) {
403
- const { getAccessToken } = useAuthContext();
404
- const orgIdRef = useRef(null);
405
- const getOrganizationId = useRef(() => orgIdRef.current).current;
406
- return /* @__PURE__ */ jsx(
407
- ApiClientProvider,
408
- {
409
- getAccessToken,
410
- getOrganizationId,
411
- isOrganizationReady: false,
412
- onError,
413
- children: /* @__PURE__ */ jsx(ServiceStackInner, { apiUrl, orgIdRef, notifications, children })
414
- }
415
- );
416
- }
417
- function ServiceStackInner({
418
- apiUrl,
419
- orgIdRef,
420
- notifications,
421
- children
422
- }) {
423
- const { apiRequest } = useApiClient(apiUrl);
424
- const resolvedNotifications = notifications ?? consoleNotificationAdapter;
425
- return /* @__PURE__ */ jsx(ProfileProvider, { apiRequest, children: /* @__PURE__ */ jsx(OrganizationProvider, { apiRequest, children: /* @__PURE__ */ jsx(OrgServiceBridge, { orgIdRef, apiRequest, notifications: resolvedNotifications, children }) }) });
426
- }
427
- function OrgServiceBridge({
428
- orgIdRef,
429
- apiRequest,
430
- notifications,
431
- children
432
- }) {
433
- const { currentWorkOSOrganizationId, isInitializing, isOrgRefreshing } = useOrganization();
434
- orgIdRef.current = currentWorkOSOrganizationId;
435
- const isReady = !!currentWorkOSOrganizationId && !isInitializing && !isOrgRefreshing;
436
- return /* @__PURE__ */ jsx(
437
- ElevasisServiceProvider,
438
- {
439
- apiRequest,
440
- workOSOrganizationId: currentWorkOSOrganizationId,
441
- isReady,
442
- children: /* @__PURE__ */ jsx(NotificationProvider, { adapter: notifications, children: /* @__PURE__ */ jsx(InitializationProvider, { children }) })
443
- }
444
- );
445
- }
446
-
447
- export { CrmActionsProvider, EMPTY_LIST_ACTIONS, ElevasisCoreProvider, ListActionsProvider, NotificationProvider, deriveActions, findListActionByAction, getListActionWorkflowId, useCrmActions, useListActions, useNotificationAdapter };
@@ -1,159 +0,0 @@
1
- import { OrganizationContext } from './chunk-DD3CCMCZ.js';
2
- import { useProfile } from './chunk-2Q2JQSQO.js';
3
- import { useAuthContext } from './chunk-BRJ3QZ4E.js';
4
- import { useState, useRef, useEffect, useCallback, createElement } from 'react';
5
- import { useQueryClient } from '@tanstack/react-query';
6
-
7
- function OrganizationProvider({ apiRequest, children }) {
8
- const { user, organizationId: workosOrgId } = useAuthContext();
9
- const { profile, error: profileError } = useProfile();
10
- const queryClient = useQueryClient();
11
- const [memberships, setMemberships] = useState([]);
12
- const [currentWorkOSOrganizationId, setCurrentWorkOSOrganizationId] = useState(null);
13
- const [currentSupabaseOrganizationId, setCurrentSupabaseOrganizationId] = useState(null);
14
- const [currentMembership, setCurrentMembership] = useState(null);
15
- const [isInitializing, setIsInitializing] = useState(true);
16
- const [isOrgRefreshing, setIsOrgRefreshing] = useState(false);
17
- const [error, setError] = useState(null);
18
- const hasInitializedRef = useRef(false);
19
- const [profileLoaded, setProfileLoaded] = useState(false);
20
- useEffect(() => {
21
- if (profile !== void 0 && profile !== null) {
22
- setProfileLoaded(true);
23
- }
24
- }, [profile]);
25
- useEffect(() => {
26
- if (profileError && isInitializing && !hasInitializedRef.current) {
27
- setIsInitializing(false);
28
- }
29
- }, [profileError, isInitializing]);
30
- useEffect(() => {
31
- if (!user) {
32
- setMemberships([]);
33
- setCurrentWorkOSOrganizationId(null);
34
- setCurrentSupabaseOrganizationId(null);
35
- setCurrentMembership(null);
36
- setIsInitializing(false);
37
- setIsOrgRefreshing(false);
38
- setError(null);
39
- hasInitializedRef.current = false;
40
- setProfileLoaded(false);
41
- }
42
- }, [user]);
43
- const applyMembership = useCallback((membership) => {
44
- setCurrentMembership(membership);
45
- setCurrentSupabaseOrganizationId(membership?.organization?.id ?? null);
46
- setCurrentWorkOSOrganizationId(membership?.organization?.workos_org_id ?? null);
47
- }, []);
48
- const selectOrganization = useCallback(
49
- (data) => {
50
- let selected = null;
51
- if (profile?.last_visited_org) {
52
- selected = data.find((m) => m.organizationId === profile.last_visited_org) ?? null;
53
- }
54
- if (!selected && workosOrgId) {
55
- selected = data.find((m) => m.organization?.workos_org_id === workosOrgId) ?? null;
56
- }
57
- if (!selected && data.length > 0) {
58
- selected = data[0];
59
- }
60
- if (selected) {
61
- applyMembership(selected);
62
- }
63
- },
64
- [profile?.last_visited_org, workosOrgId, applyMembership]
65
- );
66
- const fetchAndInitialize = useCallback(async () => {
67
- if (!user?.id || !profileLoaded) return;
68
- setError(null);
69
- if (memberships.length === 0) {
70
- setIsInitializing(true);
71
- } else {
72
- setIsOrgRefreshing(true);
73
- }
74
- try {
75
- const data = await apiRequest("/memberships/my-memberships");
76
- if (!Array.isArray(data)) {
77
- throw new Error("Invalid memberships response");
78
- }
79
- setMemberships(data);
80
- if (data.length === 0) {
81
- hasInitializedRef.current = true;
82
- return;
83
- }
84
- if (!currentWorkOSOrganizationId) {
85
- selectOrganization(data);
86
- } else {
87
- const stillPresent = data.find((m) => m.organization?.workos_org_id === currentWorkOSOrganizationId);
88
- if (!stillPresent) {
89
- applyMembership(data[0] ?? null);
90
- } else if (stillPresent.id !== currentMembership?.id) {
91
- applyMembership(stillPresent);
92
- }
93
- }
94
- hasInitializedRef.current = true;
95
- } catch (err) {
96
- setError(err instanceof Error ? err.message : "Failed to load organizations");
97
- } finally {
98
- setIsInitializing(false);
99
- setIsOrgRefreshing(false);
100
- }
101
- }, [
102
- user?.id,
103
- profileLoaded,
104
- memberships.length,
105
- apiRequest,
106
- currentWorkOSOrganizationId,
107
- currentMembership?.id,
108
- selectOrganization,
109
- applyMembership
110
- ]);
111
- useEffect(() => {
112
- if (!user?.id || !profileLoaded || hasInitializedRef.current) return;
113
- fetchAndInitialize();
114
- }, [user?.id, profileLoaded, fetchAndInitialize]);
115
- useEffect(() => {
116
- if (!hasInitializedRef.current) return;
117
- if (!workosOrgId) return;
118
- if (workosOrgId === currentWorkOSOrganizationId) return;
119
- const target = memberships.find((m) => m.organization?.workos_org_id === workosOrgId);
120
- if (!target) return;
121
- applyMembership(target);
122
- void queryClient.invalidateQueries();
123
- }, [workosOrgId, currentWorkOSOrganizationId, memberships, applyMembership, queryClient]);
124
- const switchOrganization = useCallback(
125
- (workosOrgId2) => {
126
- const target = memberships.find((m) => m.organization?.workos_org_id === workosOrgId2);
127
- if (!target) return;
128
- applyMembership(target);
129
- void queryClient.invalidateQueries();
130
- void apiRequest("/users/me", {
131
- method: "PATCH",
132
- headers: { "Content-Type": "application/json" },
133
- body: JSON.stringify({ last_visited_org: target.organizationId })
134
- }).catch((err) => {
135
- console.warn("Failed to persist last_visited_org preference:", err);
136
- });
137
- },
138
- [memberships, applyMembership, queryClient, apiRequest]
139
- );
140
- const retry = useCallback(async () => {
141
- hasInitializedRef.current = false;
142
- setError(null);
143
- await fetchAndInitialize();
144
- }, [fetchAndInitialize]);
145
- const value = {
146
- currentWorkOSOrganizationId,
147
- currentSupabaseOrganizationId,
148
- currentMembership,
149
- memberships,
150
- isInitializing,
151
- isOrgRefreshing,
152
- error,
153
- switchOrganization,
154
- retry
155
- };
156
- return createElement(OrganizationContext.Provider, { value }, children);
157
- }
158
-
159
- export { OrganizationProvider };