@digiform/wizard 0.2.9 → 0.2.11

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 (153) hide show
  1. package/core/src/types/api.js +12 -0
  2. package/core/src/types/form-config.js +60 -0
  3. package/core/src/types/form-wizard-config-schema.js +113 -0
  4. package/core/src/types/guards.js +19 -0
  5. package/core/src/types/validation.js +61 -0
  6. package/core/src/utils/apiBodyUtils.js +95 -0
  7. package/features/api-integration.d.ts +2 -0
  8. package/features/api-integration.js +17 -0
  9. package/features/dialog-system.d.ts +2 -0
  10. package/features/dialog-system.js +9 -0
  11. package/features/form-runtime.d.ts +2 -0
  12. package/features/form-runtime.js +63 -0
  13. package/features/state-management.d.ts +2 -0
  14. package/features/state-management.js +21 -0
  15. package/features/trigger-action-system.d.ts +2 -0
  16. package/features/trigger-action-system.js +12 -0
  17. package/features/validation-system.d.ts +2 -0
  18. package/features/validation-system.js +23 -0
  19. package/index.js +108 -17470
  20. package/package.json +35 -30
  21. package/styles.css +1 -1
  22. package/ui/src/component-registry/renderComponent.js +11 -0
  23. package/ui/src/components/FormLayout/FormLayout.js +135 -0
  24. package/ui/src/components/FormLayout/FormLayout.module.css.js +20 -0
  25. package/ui/src/components/GridLayout/GridLayout.js +62 -0
  26. package/ui/src/components/GridLayout/GridLayout.module.css.js +16 -0
  27. package/ui/src/components/GridLayoutColumn/GridLayoutColumn.js +37 -0
  28. package/ui/src/components/GridLayoutColumn/GridLayoutColumn.module.css.js +10 -0
  29. package/ui/src/components/ProgressLoaderBar/ProgressLoaderBar.js +108 -0
  30. package/ui/src/components/ProgressLoaderBar/ProgressLoaderBar.module.css.js +20 -0
  31. package/ui/src/components/ProgressLoaderBar/useProgressAnimation.js +31 -0
  32. package/ui/src/components/ValidationCode/ValidationCode.js +198 -0
  33. package/ui/src/components/ValidationCode/ValidationCode.module.css.js +20 -0
  34. package/ui/src/components/alert/alert.js +30 -0
  35. package/ui/src/components/alert/alert.module.css.js +14 -0
  36. package/ui/src/components/badge/badge.js +20 -0
  37. package/ui/src/components/badge/badge.module.css.js +12 -0
  38. package/ui/src/components/box/box.js +8 -0
  39. package/ui/src/components/box/box.module.css.js +8 -0
  40. package/ui/src/components/button/button.js +25 -0
  41. package/ui/src/components/button/button.module.css.js +18 -0
  42. package/ui/src/components/card/card.js +106 -0
  43. package/ui/src/components/card/card.module.css.js +44 -0
  44. package/ui/src/components/checkbox/checkbox.js +20 -0
  45. package/ui/src/components/checkbox/checkbox.module.css.js +10 -0
  46. package/ui/src/components/dialog/dialog.js +67 -0
  47. package/ui/src/components/dialog/dialog.module.css.js +20 -0
  48. package/ui/src/components/form-header-base/form-header-base.js +59 -0
  49. package/ui/src/components/form-header-base/form-header-base.module.css.js +14 -0
  50. package/ui/src/components/input/input.js +20 -0
  51. package/ui/src/components/input/input.module.css.js +8 -0
  52. package/ui/src/components/radio-group/radio-group.js +30 -0
  53. package/ui/src/components/radio-group/radio-group.module.css.js +14 -0
  54. package/ui/src/components/select/select.js +115 -0
  55. package/ui/src/components/select/select.module.css.js +32 -0
  56. package/ui/src/components/sheet/sheet.js +71 -0
  57. package/ui/src/components/sheet/sheet.module.css.js +46 -0
  58. package/ui/src/components/textarea/textarea.js +19 -0
  59. package/ui/src/components/textarea/textarea.module.css.js +8 -0
  60. package/ui/src/design-system/components/FormFieldWrapper.js +16 -0
  61. package/ui/src/lib/assets/icons/Check.js +26 -0
  62. package/ui/src/lib/assets/icons/ChevronRight.js +26 -0
  63. package/ui/src/lib/error-boundaries/BaseErrorBoundary.js +155 -0
  64. package/ui/src/lib/error-boundaries/ComponentErrorBoundary.js +153 -0
  65. package/ui/src/lib/error-boundaries/FormWizardErrorBoundary.js +107 -0
  66. package/ui/src/lib/logger.js +106 -0
  67. package/ui/src/lib/providers/FormEditingContext.js +21 -0
  68. package/ui/src/lib/queryClient.js +26 -0
  69. package/ui/src/lib/types/guards.js +11 -0
  70. package/ui/src/lib/utils/componentUtils.js +38 -0
  71. package/ui/src/lib/utils/templateDialogResolver.js +85 -0
  72. package/ui/src/lib/utils/templateUtils.js +52 -0
  73. package/ui/src/theme/ThemeProvider.js +15 -0
  74. package/wizard/src/features/api-integration/components/EnhancedActionExecutor/EnhancedActionExecutor.js +370 -0
  75. package/wizard/src/features/api-integration/services/ActionExecutor.js +339 -0
  76. package/wizard/src/features/api-integration/services/ApiCallExecutor.js +6 -0
  77. package/wizard/src/features/api-integration/services/ApiCallService.js +309 -0
  78. package/wizard/src/features/api-integration/services/DialogExecutor.js +6 -0
  79. package/wizard/src/features/api-integration/services/GenericTriggerService.js +284 -0
  80. package/wizard/src/features/api-integration/services/NavigationExecutor.js +6 -0
  81. package/wizard/src/features/dialog-system/components/ActionDialog/ActionDialog.js +115 -0
  82. package/wizard/src/features/dialog-system/components/ActionDialog/ActionDialog.module.css.js +29 -0
  83. package/wizard/src/features/dialog-system/components/ConfirmationDialog/ConfirmationDialog.js +64 -0
  84. package/wizard/src/features/dialog-system/components/ConfirmationDialog/ConfirmationDialog.module.css.js +22 -0
  85. package/wizard/src/features/dialog-system/components/EmailVerificationDialog/EmailVerificationDialog.js +149 -0
  86. package/wizard/src/features/dialog-system/components/EmailVerificationDialog/EmailVerificationDialog.module.css.js +40 -0
  87. package/wizard/src/features/form-runtime/ComponentAdapterComplete/ComponentAdapterComplete.js +107 -0
  88. package/wizard/src/features/form-runtime/ComponentAdapterComplete/ComponentAdapterComplete.module.css.js +10 -0
  89. package/wizard/src/features/form-runtime/FormWizard/FormWizard.js +107 -0
  90. package/wizard/src/features/form-runtime/FormWizard/FormWizard.module.css.js +16 -0
  91. package/wizard/src/features/form-runtime/components/FormField.js +405 -0
  92. package/wizard/src/features/form-runtime/components/FormFooter.js +209 -0
  93. package/wizard/src/features/form-runtime/components/FormHeader.js +29 -0
  94. package/wizard/src/features/form-runtime/components/FormSection/FormSection.js +279 -0
  95. package/wizard/src/features/form-runtime/components/FormSection/FormSection.module.css.js +20 -0
  96. package/wizard/src/features/form-runtime/components/FormStep/FormStep.js +167 -0
  97. package/wizard/src/features/form-runtime/components/FormStep/FormStep.module.css.js +12 -0
  98. package/wizard/src/features/form-runtime/components/ProgressLoaderRuntime.js +88 -0
  99. package/wizard/src/features/form-runtime/components/StepProgressIndicator/StepProgressIndicator.js +61 -0
  100. package/wizard/src/features/form-runtime/components/StepProgressIndicator/StepProgressIndicator.module.css.js +34 -0
  101. package/wizard/src/features/form-runtime/components/displayValue/displayValue.js +21 -0
  102. package/wizard/src/features/form-runtime/components/displayValue/displayValue.module.css.js +10 -0
  103. package/wizard/src/features/form-runtime/components/renderers/DisplayModeRenderer/DisplayModeRenderer.js +28 -0
  104. package/wizard/src/features/form-runtime/components/renderers/DisplayModeRenderer/DisplayModeRenderer.module.css.js +8 -0
  105. package/wizard/src/features/form-runtime/components/renderers/InteractiveFieldRenderer/InteractiveFieldRenderer.js +56 -0
  106. package/wizard/src/features/form-runtime/components/renderers/InteractiveFieldRenderer/InteractiveFieldRenderer.module.css.js +8 -0
  107. package/wizard/src/features/form-runtime/config/configResolver.js +38 -0
  108. package/wizard/src/features/form-runtime/config/templateConfig.js +156 -0
  109. package/wizard/src/features/form-runtime/config/templateLoader.js +265 -0
  110. package/wizard/src/features/form-runtime/config/templateUtils.js +14 -0
  111. package/wizard/src/features/form-runtime/context/LoaderContext.js +36 -0
  112. package/wizard/src/features/form-runtime/hooks/useApiActions.js +60 -0
  113. package/wizard/src/features/form-runtime/hooks/useComponentTriggers.js +102 -0
  114. package/wizard/src/features/form-runtime/hooks/useComponentVisibility.js +18 -0
  115. package/wizard/src/features/form-runtime/hooks/useFieldEventHandlers.js +61 -0
  116. package/wizard/src/features/form-runtime/hooks/useFormContext.js +13 -0
  117. package/wizard/src/features/form-runtime/hooks/useFormFieldState.js +40 -0
  118. package/wizard/src/features/form-runtime/hooks/useValidationEvents.js +39 -0
  119. package/wizard/src/features/form-runtime/utils/componentDisplayValue.js +22 -0
  120. package/wizard/src/features/form-runtime/utils/errorUtils.js +93 -0
  121. package/wizard/src/features/form-runtime/utils/fieldHelpers.js +17 -0
  122. package/wizard/src/features/form-runtime/utils/formDataBuilder.js +10 -0
  123. package/wizard/src/features/form-runtime/utils/formDirtyStateSync.js +52 -0
  124. package/wizard/src/features/form-runtime/utils/logger.js +111 -0
  125. package/wizard/src/features/form-runtime/utils/validation.js +100 -0
  126. package/wizard/src/features/form-runtime/utils/validationUX.js +58 -0
  127. package/wizard/src/features/form-runtime/utils/visibilityUtils.js +77 -0
  128. package/wizard/src/features/state-management/machines/actions/componentActions.js +215 -0
  129. package/wizard/src/features/state-management/machines/actions/navigationActions.js +122 -0
  130. package/wizard/src/features/state-management/machines/actions/saveActions.js +101 -0
  131. package/wizard/src/features/state-management/machines/componentTriggerEngine.js +598 -0
  132. package/wizard/src/features/state-management/machines/formMachine.js +1565 -0
  133. package/wizard/src/features/state-management/machines/guards/navigationGuards.js +59 -0
  134. package/wizard/src/features/state-management/machines/guards/saveGuards.js +21 -0
  135. package/wizard/src/features/state-management/machines/guards/triggerGuards.js +11 -0
  136. package/wizard/src/features/state-management/machines/helpers/triggerHelpers.js +12 -0
  137. package/wizard/src/features/state-management/machines/performance.js +56 -0
  138. package/wizard/src/features/state-management/machines/useFormMachine.js +412 -0
  139. package/wizard/src/features/trigger-action-system/components/ActionLoadingIndicator/ActionLoadingIndicator.js +46 -0
  140. package/wizard/src/features/trigger-action-system/components/ActionLoadingIndicator/ActionLoadingIndicator.module.css.js +30 -0
  141. package/wizard/src/features/trigger-action-system/components/ActionManager.js +108 -0
  142. package/wizard/src/features/trigger-action-system/components/ComponentAlert/ComponentAlert.js +10 -0
  143. package/wizard/src/features/trigger-action-system/components/ComponentAlert/ComponentAlert.module.css.js +8 -0
  144. package/wizard/src/features/trigger-action-system/utils/GenericTriggerEngine.js +376 -0
  145. package/wizard/src/features/validation-system/components/ValidationDebugger.js +69 -0
  146. package/wizard/src/features/validation-system/validation/ActionValidation.js +234 -0
  147. package/wizard/src/features/validation-system/validation/SchemaBuilder.js +239 -0
  148. package/wizard/src/features/validation-system/validation/ValidationCache.js +76 -0
  149. package/wizard/src/features/validation-system/validation/ValidationEngine.js +97 -0
  150. package/wizard/src/features/validation-system/validation/ValidationExecutor.js +138 -0
  151. package/wizard/src/features/validation-system/validation/tanstackSchemaAdapter.js +17 -0
  152. package/wizard/src/features/validation-system/validation/validationService.js +74 -0
  153. package/wizard/src/renderer/wizardRenderer.js +123 -0
@@ -0,0 +1,339 @@
1
+ "use client";
2
+ /* empty css */
3
+ import { isTemplateDialogConfig as m } from "../../../../../ui/src/lib/types/guards.js";
4
+ import { ActionValidator as v, ActionValidationError as C } from "../../validation-system/validation/ActionValidation.js";
5
+ import { memo as A, useCallback as E, useEffect as D } from "react";
6
+ import { ApiCallService as S } from "./ApiCallService.js";
7
+ import { resolveTemplateDialog as T } from "../../../../../ui/src/lib/utils/templateDialogResolver.js";
8
+ const I = A(
9
+ ({
10
+ actions: s,
11
+ trigger: e,
12
+ formData: t,
13
+ onComplete: i,
14
+ onError: n,
15
+ onFieldUpdate: l,
16
+ onShowDialog: a,
17
+ onNavigate: f,
18
+ machineRef: r
19
+ }) => {
20
+ const y = E(async () => {
21
+ console.log("ActionExecutor: Starting action execution", {
22
+ actions: s,
23
+ trigger: e
24
+ });
25
+ const u = s.filter(
26
+ (o) => o.trigger === e
27
+ );
28
+ if (console.log("ActionExecutor: Filtered actions", {
29
+ triggeredActions: u,
30
+ trigger: e
31
+ }), u.length === 0) {
32
+ console.log("ActionExecutor: No actions to execute"), r?.send({
33
+ type: "ACTIONS_COMPLETED",
34
+ results: {}
35
+ }), i({});
36
+ return;
37
+ }
38
+ const d = [];
39
+ for (const o of u) {
40
+ const c = v.validateAction(o);
41
+ c.isValid || d.push(
42
+ `Action '${o.id}': ${c.errors.join(", ")}`
43
+ );
44
+ }
45
+ if (d.length > 0) {
46
+ const o = new C(
47
+ "validation-error",
48
+ "validation",
49
+ `Action validation failed: ${d.join("; ")}`,
50
+ { validationErrors: d }
51
+ );
52
+ r?.send({
53
+ type: "ACTIONS_COMPLETED",
54
+ results: {}
55
+ }), n(o);
56
+ return;
57
+ }
58
+ const x = [...u].sort(
59
+ (o, c) => o.order - c.order
60
+ ), g = {};
61
+ try {
62
+ for (const o of x)
63
+ r?.send({ type: "ACTION_START", actionId: o.id });
64
+ for (const o of x)
65
+ try {
66
+ let c = null;
67
+ switch (o.type) {
68
+ case "apiCall": {
69
+ console.log("ActionExecutor: Executing API call", {
70
+ action: o,
71
+ config: o.config
72
+ }), c = await new S({ onFieldUpdate: l }).executeApiCall(
73
+ o.config,
74
+ t
75
+ ), console.log("ActionExecutor: API call completed", { result: c });
76
+ break;
77
+ }
78
+ case "showDialog": {
79
+ console.log("🎯 ActionExecutor: Executing showDialog", {
80
+ action: o,
81
+ config: o.config
82
+ }), console.log(
83
+ "🔧 ActionExecutor: Creating DialogExecutorService"
84
+ );
85
+ const p = new b();
86
+ console.log("🚀 ActionExecutor: Calling executor.execute"), c = await p.execute(
87
+ o.config,
88
+ t,
89
+ a
90
+ ), console.log("✅ ActionExecutor: showDialog completed", {
91
+ result: c
92
+ });
93
+ break;
94
+ }
95
+ case "navigate": {
96
+ c = await new w().execute(
97
+ o.config,
98
+ f
99
+ );
100
+ break;
101
+ }
102
+ case "executeVerifyDialog": {
103
+ console.log(
104
+ "🔧 ActionExecutor: Executing executeVerifyDialog",
105
+ {
106
+ action: o,
107
+ config: o.config
108
+ }
109
+ ), c = await new O().execute(
110
+ o.config,
111
+ t,
112
+ a
113
+ ), console.log(
114
+ "✅ ActionExecutor: executeVerifyDialog completed",
115
+ {
116
+ result: c
117
+ }
118
+ );
119
+ break;
120
+ }
121
+ default:
122
+ throw new Error(`Unknown action type: ${o.type}`);
123
+ }
124
+ g[o.id] = c, r?.send({
125
+ type: "ACTION_SUCCESS",
126
+ actionId: o.id,
127
+ result: c
128
+ });
129
+ } catch (c) {
130
+ r?.send({
131
+ type: "ACTION_ERROR",
132
+ actionId: o.id,
133
+ error: c
134
+ }), g[o.id] = { error: c.message };
135
+ }
136
+ r?.send({
137
+ type: "ACTIONS_COMPLETED",
138
+ results: g
139
+ }), i(g);
140
+ } catch (o) {
141
+ r?.send({
142
+ type: "ACTIONS_COMPLETED",
143
+ results: g
144
+ }), n(o);
145
+ }
146
+ }, [
147
+ s,
148
+ e,
149
+ t,
150
+ i,
151
+ n,
152
+ l,
153
+ a,
154
+ f,
155
+ r
156
+ ]);
157
+ return D(() => {
158
+ y();
159
+ }, [y]), null;
160
+ }
161
+ );
162
+ I.displayName = "ActionExecutor";
163
+ class b {
164
+ async execute(e, t, i) {
165
+ console.log("🚀 DialogExecutorService.execute STARTED", {
166
+ config: e,
167
+ formData: t
168
+ });
169
+ const n = this.resolveDialogConfig(e, t);
170
+ return console.log("🔄 DialogExecutorService: Config resolved", {
171
+ resolvedConfig: n
172
+ }), console.log("📞 DialogExecutorService: Calling onShowDialog", {
173
+ resolvedConfig: n
174
+ }), i(n), console.log("✅ DialogExecutorService.execute COMPLETED", {
175
+ resolvedConfig: n
176
+ }), n;
177
+ }
178
+ resolveDialogConfig(e, t) {
179
+ if (console.log("🔍 DialogExecutorService.resolveDialogConfig input:", {
180
+ config: e,
181
+ formData: t
182
+ }), m(e)) {
183
+ console.log("✅ Detected as TemplateDialogConfig");
184
+ const n = this.resolveTemplateDialogWithActions(e);
185
+ console.log("🔄 Resolved template config:", { baseConfig: n });
186
+ const l = this.interpolateDialogConfig(n, t);
187
+ return console.log("✨ Final interpolated config:", { finalConfig: l }), l;
188
+ }
189
+ console.log("✅ Treating as direct DialogConfig");
190
+ const i = this.interpolateDialogConfig(
191
+ e,
192
+ t
193
+ );
194
+ return console.log("✨ Final direct config:", { finalConfig: i }), i;
195
+ }
196
+ interpolateDialogConfig(e, t) {
197
+ return {
198
+ ...e,
199
+ content: this.interpolateTemplate(e.content, t),
200
+ title: this.interpolateTemplate(e.title, t)
201
+ };
202
+ }
203
+ resolveTemplateDialogWithActions(e) {
204
+ console.log("🔄 Resolving template with actions:", e);
205
+ const t = e.template, i = t.config;
206
+ if (t.typeId === "confirmation-dialog") {
207
+ console.log(
208
+ "✅ Processing confirmation-dialog template:",
209
+ i
210
+ );
211
+ const n = {
212
+ title: i.title || "Confirm Action",
213
+ content: i.message || i.content || "Are you sure you want to proceed?",
214
+ type: "modal",
215
+ size: "medium",
216
+ dismissible: !0,
217
+ buttons: [
218
+ {
219
+ id: "cancel-btn",
220
+ label: i.cancelButtonLabel || "Cancel",
221
+ variant: "secondary",
222
+ action: i.onCancelAction || { type: "close" }
223
+ },
224
+ {
225
+ id: "confirm-btn",
226
+ label: i.confirmButtonLabel || "Confirm",
227
+ variant: i.confirmButtonVariant || "primary",
228
+ action: i.onConfirmAction || {
229
+ type: "navigate",
230
+ direction: "next"
231
+ }
232
+ }
233
+ ],
234
+ // Add template metadata for runtime behavior
235
+ templateMetadata: {
236
+ typeId: "confirmation-dialog",
237
+ showIcon: i.showIcon,
238
+ iconType: i.iconType
239
+ }
240
+ };
241
+ return console.log("✨ Resolved confirmation dialog config:", n), n;
242
+ }
243
+ return console.log(
244
+ "🔄 Falling back to resolveTemplateDialog for typeId:",
245
+ t.typeId
246
+ ), T(e);
247
+ }
248
+ interpolateTemplate(e, t) {
249
+ return e.replace(/\$\{data\.([^}]+)\}/g, (i, n) => {
250
+ const l = t[n];
251
+ return l != null ? String(l) : i;
252
+ });
253
+ }
254
+ }
255
+ class w {
256
+ async execute(e, t) {
257
+ return t(e), e;
258
+ }
259
+ }
260
+ class O {
261
+ async execute(e, t, i) {
262
+ console.log("🚀 GenericVerifyDialogService.execute STARTED", {
263
+ config: e,
264
+ formData: t
265
+ });
266
+ const n = e.postAction || { type: "close" };
267
+ let l;
268
+ switch (n.type) {
269
+ case "close":
270
+ case "saveSection":
271
+ l = {
272
+ type: "updateOriginalValue",
273
+ componentId: e.componentId
274
+ };
275
+ break;
276
+ case "nextStep":
277
+ l = {
278
+ type: "navigate",
279
+ direction: "next",
280
+ updateOriginalValue: !0,
281
+ componentId: e.componentId
282
+ };
283
+ break;
284
+ case "navigate":
285
+ l = {
286
+ type: "navigate",
287
+ direction: n.direction,
288
+ targetStep: n.targetStep,
289
+ updateOriginalValue: !0,
290
+ componentId: e.componentId
291
+ };
292
+ break;
293
+ default:
294
+ l = {
295
+ type: "updateOriginalValue",
296
+ componentId: e.componentId
297
+ };
298
+ }
299
+ const a = {
300
+ title: "Verify Changes",
301
+ content: "Please verify your changes before continuing.",
302
+ type: "modal",
303
+ size: "medium",
304
+ dismissible: !0,
305
+ buttons: [
306
+ {
307
+ id: "cancel-btn",
308
+ label: "Cancel",
309
+ variant: "secondary",
310
+ action: { type: "close" }
311
+ },
312
+ {
313
+ id: "verify-btn",
314
+ label: "Verify",
315
+ variant: "primary",
316
+ action: { type: "close" }
317
+ // This will be overridden by templateMetadata.onVerifiedAction
318
+ }
319
+ ],
320
+ // Add template metadata to identify this as a verification dialog
321
+ templateMetadata: {
322
+ typeId: "verify-dialog",
323
+ isGeneric: !0,
324
+ componentId: e.componentId,
325
+ onVerifiedAction: l
326
+ // This will be used by EmailVerificationDialog
327
+ }
328
+ };
329
+ return console.log("📞 GenericVerifyDialogService: Calling onShowDialog", {
330
+ defaultDialogConfig: a
331
+ }), i(a), console.log("✅ GenericVerifyDialogService.execute COMPLETED", {
332
+ defaultDialogConfig: a
333
+ }), a;
334
+ }
335
+ }
336
+ export {
337
+ I as ActionExecutor,
338
+ I as default
339
+ };
@@ -0,0 +1,6 @@
1
+ "use client";
2
+ const l = () => null;
3
+ export {
4
+ l as ApiCallExecutor,
5
+ l as default
6
+ };
@@ -0,0 +1,309 @@
1
+ "use client";
2
+ import { compileApiRequestBody as h } from "../../../../../core/src/utils/apiBodyUtils.js";
3
+ import { ActionValidationError as c } from "../../validation-system/validation/ActionValidation.js";
4
+ import "@tanstack/react-query";
5
+ function y(l) {
6
+ return l !== null && typeof l == "object" && !Array.isArray(l);
7
+ }
8
+ function d(l) {
9
+ return typeof l == "object" && l !== null && "message" in l && typeof l.message == "string";
10
+ }
11
+ class C {
12
+ options;
13
+ constructor(e = {}) {
14
+ this.options = e;
15
+ }
16
+ // Generate cache key for API call
17
+ generateCacheKey(e, r) {
18
+ if (e.cacheKey)
19
+ return this.interpolateTemplate(e.cacheKey, r);
20
+ const t = this.interpolateTemplate(e.url, r), i = e.method;
21
+ let s = "";
22
+ if (i === "POST" || i === "PUT")
23
+ try {
24
+ const n = h(e, r);
25
+ s = n ? `:${JSON.stringify(n)}` : "";
26
+ } catch {
27
+ s = "";
28
+ }
29
+ return `api-call:${i}:${t}${s}`;
30
+ }
31
+ // Create query options for React Query
32
+ createQueryOptions(e, r) {
33
+ return {
34
+ queryKey: [this.generateCacheKey(e, r)],
35
+ queryFn: () => this.executeApiCall(e, r),
36
+ gcTime: e.cacheTTL || 300 * 1e3,
37
+ // 5 minutes default
38
+ staleTime: e.staleTime || 30 * 1e3,
39
+ // 30 seconds default
40
+ retry: e.retryCount || 0,
41
+ throwOnError: !e.cacheOnError
42
+ };
43
+ }
44
+ // Execute API call with automatic response mapping
45
+ async executeApiCall(e, r) {
46
+ const t = await this.makeApiCall(e, r);
47
+ return e.method === "GET" && e.fieldMappings && this.options.onFieldUpdate && this.applyFlattenedResponseMappings(
48
+ t,
49
+ e.fieldMappings,
50
+ this.options.onFieldUpdate
51
+ ), t;
52
+ }
53
+ // private extractRequestData(
54
+ // _config: ApiCallConfig,
55
+ // _formData: FormData
56
+ // ): Record<string, unknown> {
57
+ // // For now, just return empty object since we're focusing on response mappings
58
+ // // Request mappings can be added later if needed
59
+ // return {};
60
+ // }
61
+ async makeApiCall(e, r) {
62
+ let t = this.interpolateTemplate(e.url, r);
63
+ const i = this.buildQueryParams(e, r);
64
+ if (i.size > 0) {
65
+ const o = new URL(t, window.location.origin);
66
+ i.forEach((p, m) => {
67
+ o.searchParams.set(m, p);
68
+ }), t = o.toString();
69
+ }
70
+ const s = this.buildHeaders(e, r);
71
+ try {
72
+ new URL(t, window.location.origin);
73
+ } catch {
74
+ throw new c(
75
+ "api-call-error",
76
+ "apiCall",
77
+ `Invalid URL: ${t}`,
78
+ { url: t, originalUrl: e.url }
79
+ );
80
+ }
81
+ const n = {
82
+ method: e.method,
83
+ headers: s
84
+ };
85
+ if (e.method === "POST" || e.method === "PUT")
86
+ try {
87
+ const o = h(e, r);
88
+ o && (n.body = o, s["Content-Type"] = s["Content-Type"] || "application/json");
89
+ } catch (o) {
90
+ throw new c(
91
+ "api-call-error",
92
+ "apiCall",
93
+ `Failed to compile request body: ${o.message}`,
94
+ { config: e, formData: r }
95
+ );
96
+ }
97
+ const a = new AbortController(), u = setTimeout(
98
+ () => a.abort(),
99
+ e.timeout || 1e4
100
+ );
101
+ try {
102
+ const o = await fetch(t, {
103
+ ...n,
104
+ signal: a.signal
105
+ });
106
+ if (clearTimeout(u), !o.ok) {
107
+ const p = await o.text().catch(() => "Unknown error");
108
+ throw new c(
109
+ "api-call-error",
110
+ "apiCall",
111
+ `API call failed: ${o.status} ${o.statusText}`,
112
+ {
113
+ status: o.status,
114
+ statusText: o.statusText,
115
+ errorText: p,
116
+ url: t
117
+ }
118
+ );
119
+ }
120
+ try {
121
+ return await o.json();
122
+ } catch {
123
+ return await o.text();
124
+ }
125
+ } catch (o) {
126
+ throw clearTimeout(u), o instanceof c ? o : o instanceof DOMException && o.name === "AbortError" ? new c(
127
+ "api-call-error",
128
+ "apiCall",
129
+ `API call timed out after ${e.timeout || 1e4}ms`,
130
+ { url: t, timeout: e.timeout || 1e4 }
131
+ ) : this.isCorsError(o, t) ? new c(
132
+ "api-cors-error",
133
+ "apiCall",
134
+ "Unable to connect to the external service due to security restrictions. This typically happens when the target server doesn't allow cross-origin requests from this website.",
135
+ {
136
+ url: t,
137
+ originalError: o.message,
138
+ errorType: "CORS",
139
+ userFriendlyMessage: "The external service is not accessible from this application due to security policies.",
140
+ suggestedActions: [
141
+ "Contact the API provider to enable CORS for this domain",
142
+ "Use a server-side proxy to make the API call",
143
+ "Check if the API endpoint URL is correct"
144
+ ]
145
+ }
146
+ ) : this.isNetworkError(o) ? new c(
147
+ "api-network-error",
148
+ "apiCall",
149
+ "Failed to connect to the external service. Please check your internet connection or try again later.",
150
+ {
151
+ url: t,
152
+ originalError: o.message,
153
+ errorType: "NETWORK",
154
+ userFriendlyMessage: "Unable to connect to the external service. This could be due to network issues or the service being unavailable.",
155
+ suggestedActions: [
156
+ "Check your internet connection",
157
+ "Try again in a few moments",
158
+ "Verify the API endpoint is accessible"
159
+ ]
160
+ }
161
+ ) : new c(
162
+ "api-call-error",
163
+ "apiCall",
164
+ `Network error: ${o.message}`,
165
+ {
166
+ url: t,
167
+ originalError: o.message,
168
+ userFriendlyMessage: "An unexpected error occurred while calling the external service."
169
+ }
170
+ );
171
+ }
172
+ }
173
+ /**
174
+ * Detects if an error is likely a CORS error
175
+ */
176
+ isCorsError(e, r) {
177
+ const t = d(e) ? e.message.toLowerCase() : "", s = [
178
+ "cors",
179
+ "cross-origin",
180
+ "access to fetch",
181
+ "blocked by cors policy",
182
+ "no 'access-control-allow-origin'",
183
+ "preflight",
184
+ "cors error"
185
+ ].some(
186
+ (u) => t.includes(u)
187
+ ), n = r.startsWith("http") && !r.includes(window.location.hostname), a = e instanceof TypeError && t.includes("failed to fetch") && n;
188
+ return s || a;
189
+ }
190
+ /**
191
+ * Detects if an error is a network-related error (but not CORS)
192
+ */
193
+ isNetworkError(e) {
194
+ if (this.isCorsError(e, "")) return !1;
195
+ const r = d(e) ? e.message.toLowerCase() : "", t = [
196
+ "network error",
197
+ "connection refused",
198
+ "connection timeout",
199
+ "connection reset",
200
+ "dns",
201
+ "name resolution failed",
202
+ "unreachable",
203
+ "connection failed"
204
+ ], i = e instanceof TypeError && r.includes("failed to fetch");
205
+ return t.some((s) => r.includes(s)) || i;
206
+ }
207
+ applyFlattenedResponseMappings(e, r, t) {
208
+ console.log("🔄 Applying response mappings:", {
209
+ response: e,
210
+ mappings: r
211
+ });
212
+ for (const [i, s] of Object.entries(r)) {
213
+ const n = this.getValueFromPath(e, i), a = this.extractFieldNameFromTemplate(s);
214
+ console.log("📝 Field mapping:", {
215
+ apiField: i,
216
+ formFieldTemplate: s,
217
+ actualFieldName: a,
218
+ rawValue: n
219
+ }), t(a, n);
220
+ }
221
+ }
222
+ /**
223
+ * Extract the actual field name from a template string
224
+ * E.g., "${step-1.username}" -> "username"
225
+ */
226
+ extractFieldNameFromTemplate(e) {
227
+ if (e.startsWith("${") && e.endsWith("}")) {
228
+ const t = e.slice(2, -1).split(".");
229
+ return t[t.length - 1];
230
+ }
231
+ return e;
232
+ }
233
+ getValueFromPath(e, r) {
234
+ return r.split(".").reduce((t, i) => {
235
+ if (y(t))
236
+ return t[i];
237
+ }, e);
238
+ }
239
+ // private _setValueAtPath(obj: UnknownRecord, path: string, value: unknown): void {
240
+ // const keys = path.split(".");
241
+ // const lastKey = keys.pop()!;
242
+ // const target = keys.reduce((current: UnknownRecord, key: string): UnknownRecord => {
243
+ // if (!isRecord(current[key])) {
244
+ // current[key] = {};
245
+ // }
246
+ // return current[key] as UnknownRecord;
247
+ // }, obj);
248
+ // target[lastKey] = value;
249
+ // }
250
+ // private _transformValue(value: unknown, transform?: string): unknown {
251
+ // if (!transform || transform === "none" || value == null) return value;
252
+ // switch (transform) {
253
+ // case "uppercase":
254
+ // return String(value).toUpperCase();
255
+ // case "lowercase":
256
+ // return String(value).toLowerCase();
257
+ // case "trim":
258
+ // return String(value).trim();
259
+ // default:
260
+ // return value;
261
+ // }
262
+ // }
263
+ buildHeaders(e, r) {
264
+ const t = {}, i = e.headers || e.headersConfig || [];
265
+ for (const s of i)
266
+ if (s.key.trim() && s.value.trim()) {
267
+ const n = this.interpolateTemplate(
268
+ s.value,
269
+ r
270
+ );
271
+ t[s.key] = n;
272
+ }
273
+ return t;
274
+ }
275
+ buildQueryParams(e, r) {
276
+ const t = new URLSearchParams(), i = e.params || e.paramsConfig || [];
277
+ for (const s of i)
278
+ if (s.key.trim() && s.value.trim()) {
279
+ const n = this.interpolateTemplate(
280
+ s.value,
281
+ r
282
+ );
283
+ t.set(s.key, n);
284
+ }
285
+ return t;
286
+ }
287
+ interpolateTemplate(e, r) {
288
+ let t = e.replace(
289
+ /\$\{data\.([^}]+)\}/g,
290
+ (i, s) => {
291
+ const n = this.getValueFromPath(r, s);
292
+ return n != null ? String(n) : i;
293
+ }
294
+ );
295
+ return t = t.replace(/\$\{([^}]+)\}/g, (i, s) => {
296
+ if (i.includes("data.")) return i;
297
+ if (s.includes(".")) {
298
+ const a = s.split("."), u = a[a.length - 1], o = r[u];
299
+ return o != null ? String(o) : i;
300
+ }
301
+ const n = this.getValueFromPath(r, s);
302
+ return n != null ? String(n) : i;
303
+ }), t;
304
+ }
305
+ }
306
+ export {
307
+ C as ApiCallService,
308
+ C as default
309
+ };
@@ -0,0 +1,6 @@
1
+ "use client";
2
+ const e = () => null;
3
+ export {
4
+ e as DialogExecutor,
5
+ e as default
6
+ };