@nordcraft/runtime 1.0.14 → 1.0.16

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.
@@ -18,14 +18,13 @@ import {
18
18
  isJsonStreamHeader,
19
19
  isTextHeader,
20
20
  } from '@nordcraft/core/dist/api/headers'
21
- import type { ActionModel } from '@nordcraft/core/dist/component/component.types'
21
+ import type { ComponentData } from '@nordcraft/core/dist/component/component.types'
22
22
  import type {
23
23
  Formula,
24
24
  FormulaContext,
25
- ValueOperationValue,
26
25
  } from '@nordcraft/core/dist/formula/formula'
27
26
  import { applyFormula } from '@nordcraft/core/dist/formula/formula'
28
- import type { NestedOmit, RequireFields } from '@nordcraft/core/dist/types'
27
+ import type { NestedOmit } from '@nordcraft/core/dist/types'
29
28
  import {
30
29
  omitPaths,
31
30
  sortObjectEntries,
@@ -34,21 +33,27 @@ import { PROXY_URL_HEADER, validateUrl } from '@nordcraft/core/dist/utils/url'
34
33
  import { isDefined } from '@nordcraft/core/dist/utils/util'
35
34
  import { handleAction } from '../events/handleAction'
36
35
  import type { Signal } from '../signal/signal'
37
- import type { ComponentContext, ContextApi } from '../types'
36
+ import type { ComponentContext, ContextApiV2 } from '../types'
38
37
 
39
38
  /**
40
39
  * Set up an api v2 for a component.
41
40
  */
42
- export function createAPI(
43
- apiRequest: ApiRequest,
44
- ctx: ComponentContext,
45
- ): RequireFields<ContextApi, 'update' | 'triggerActions'> {
41
+ export function createAPI({
42
+ apiRequest,
43
+ componentData: initialComponentData,
44
+ ctx,
45
+ }: {
46
+ apiRequest: ApiRequest
47
+ componentData: ComponentData
48
+ ctx: ComponentContext
49
+ }): ContextApiV2 {
46
50
  // If `__toddle` isn't found it is in a web component context. We behave as if the page isn't loaded.
47
51
  let timer: any = null
48
52
  let api = { ...apiRequest }
49
53
 
50
54
  function constructRequest(
51
55
  api: ApiRequest,
56
+ componentData: ComponentData,
52
57
  ): ReturnType<typeof createApiRequest> {
53
58
  // Get baseUrl and validate it. (It wont be in web component context)
54
59
  let baseUrl: string | undefined = window.origin
@@ -60,7 +65,7 @@ export function createAPI(
60
65
 
61
66
  const request = createApiRequest({
62
67
  api,
63
- formulaContext: getFormulaContext(api),
68
+ formulaContext: getFormulaContext(api, componentData),
64
69
  baseUrl,
65
70
  defaultHeaders: undefined,
66
71
  })
@@ -81,7 +86,10 @@ export function createAPI(
81
86
  }
82
87
 
83
88
  // Create the formula context for the api
84
- function getFormulaContext(api: ApiRequest): FormulaContext {
89
+ function getFormulaContext(
90
+ api: ApiRequest,
91
+ componentData: ComponentData | undefined,
92
+ ): FormulaContext {
85
93
  // Use the general formula context to evaluate the arguments of the api
86
94
  const formulaContext = {
87
95
  data: ctx.dataSignal.get(),
@@ -102,6 +110,7 @@ export function createAPI(
102
110
  }, {})
103
111
 
104
112
  const data = {
113
+ ...componentData,
105
114
  ...formulaContext.data,
106
115
  ApiInputs: {
107
116
  ...evaluatedInputs,
@@ -119,15 +128,16 @@ export function createAPI(
119
128
  }
120
129
  }
121
130
 
122
- function handleRedirectRules(api: ApiRequest) {
131
+ function handleRedirectRules(api: ApiRequest, componentData: ComponentData) {
123
132
  for (const [ruleName, rule] of sortObjectEntries(
124
133
  api.redirectRules ?? {},
125
134
  ([_, rule]) => rule.index,
126
135
  )) {
136
+ const formulaContext = getFormulaContext(api, componentData)
127
137
  const location = applyFormula(rule.formula, {
128
- ...getFormulaContext(api),
138
+ ...formulaContext,
129
139
  data: {
130
- ...getFormulaContext(api).data,
140
+ ...formulaContext.data,
131
141
  Apis: {
132
142
  [api.name]: ctx.dataSignal.get().Apis?.[api.name] as ApiStatus,
133
143
  },
@@ -154,15 +164,22 @@ export function createAPI(
154
164
  }
155
165
  }
156
166
 
157
- function triggerActions(
158
- eventName: 'message' | 'success' | 'failed',
159
- api: ApiRequest,
167
+ function triggerActions({
168
+ eventName,
169
+ api,
170
+ data,
171
+ componentData,
172
+ }: {
173
+ eventName: 'message' | 'success' | 'failed'
174
+ api: ApiRequest
160
175
  data: {
161
176
  body: unknown
162
177
  status?: number
163
178
  headers?: Record<string, string>
164
- },
165
- ) {
179
+ }
180
+ componentData: ComponentData
181
+ }) {
182
+ const formulaContext = getFormulaContext(api, componentData)
166
183
  switch (eventName) {
167
184
  case 'message': {
168
185
  const event = createApiEvent('message', data.body)
@@ -170,8 +187,7 @@ export function createAPI(
170
187
  handleAction(
171
188
  action,
172
189
  {
173
- ...getFormulaContext(api).data,
174
- ...ctx.dataSignal.get(),
190
+ ...formulaContext.data,
175
191
  Event: event,
176
192
  },
177
193
  ctx,
@@ -186,8 +202,7 @@ export function createAPI(
186
202
  handleAction(
187
203
  action,
188
204
  {
189
- ...getFormulaContext(api).data,
190
- ...ctx.dataSignal.get(),
205
+ ...formulaContext.data,
191
206
  Event: event,
192
207
  },
193
208
  ctx,
@@ -205,8 +220,7 @@ export function createAPI(
205
220
  handleAction(
206
221
  action,
207
222
  {
208
- ...getFormulaContext(api).data,
209
- ...ctx.dataSignal.get(),
223
+ ...formulaContext.data,
210
224
  Event: event,
211
225
  },
212
226
  ctx,
@@ -218,15 +232,21 @@ export function createAPI(
218
232
  }
219
233
  }
220
234
 
221
- function apiSuccess(
222
- api: ApiRequest,
235
+ function apiSuccess({
236
+ api,
237
+ componentData,
238
+ data,
239
+ performance,
240
+ }: {
241
+ api: ApiRequest
242
+ componentData: ComponentData
223
243
  data: {
224
244
  body: unknown
225
245
  status?: number
226
246
  headers?: Record<string, string>
227
- },
228
- performance: ApiPerformance,
229
- ) {
247
+ }
248
+ performance: ApiPerformance
249
+ }) {
230
250
  const latestRequestStart =
231
251
  ctx.dataSignal.get().Apis?.[api.name]?.response?.performance?.requestStart
232
252
  if (
@@ -252,7 +272,7 @@ export function createAPI(
252
272
  },
253
273
  },
254
274
  })
255
- const appliedRedirectRule = handleRedirectRules(api)
275
+ const appliedRedirectRule = handleRedirectRules(api, componentData)
256
276
  if (appliedRedirectRule) {
257
277
  ctx.dataSignal.set({
258
278
  ...ctx.dataSignal.get(),
@@ -276,15 +296,21 @@ export function createAPI(
276
296
  }
277
297
  }
278
298
 
279
- function apiError(
280
- api: ApiRequest,
299
+ function apiError({
300
+ api,
301
+ componentData,
302
+ data,
303
+ performance,
304
+ }: {
305
+ api: ApiRequest
306
+ componentData: ComponentData
281
307
  data: {
282
308
  body: unknown
283
309
  status?: number
284
310
  headers?: Record<string, string>
285
- },
286
- performance: ApiPerformance,
287
- ) {
311
+ }
312
+ performance: ApiPerformance
313
+ }) {
288
314
  const latestRequestStart =
289
315
  ctx.dataSignal.get().Apis?.[api.name]?.response?.performance?.requestStart
290
316
  if (
@@ -309,7 +335,7 @@ export function createAPI(
309
335
  },
310
336
  },
311
337
  })
312
- const appliedRedirectRule = handleRedirectRules(api)
338
+ const appliedRedirectRule = handleRedirectRules(api, componentData)
313
339
  if (appliedRedirectRule) {
314
340
  ctx.dataSignal.set({
315
341
  ...ctx.dataSignal.get(),
@@ -334,11 +360,17 @@ export function createAPI(
334
360
  }
335
361
 
336
362
  // Execute the request - potentially to the cloudflare Query proxy
337
- async function execute(
338
- api: ApiRequest,
339
- url: URL,
340
- requestSettings: ToddleRequestInit,
341
- ) {
363
+ async function execute({
364
+ api,
365
+ url,
366
+ requestSettings,
367
+ componentData,
368
+ }: {
369
+ api: ApiRequest
370
+ url: URL
371
+ requestSettings: ToddleRequestInit
372
+ componentData: ComponentData
373
+ }) {
342
374
  const run = async () => {
343
375
  const performance: ApiPerformance = {
344
376
  requestStart: Date.now(),
@@ -362,7 +394,7 @@ export function createAPI(
362
394
  const proxy = api.server?.proxy
363
395
  ? (applyFormula(
364
396
  api.server.proxy.enabled.formula,
365
- getFormulaContext(api),
397
+ getFormulaContext(api, componentData),
366
398
  ) ?? false)
367
399
  : false
368
400
 
@@ -384,14 +416,24 @@ export function createAPI(
384
416
  }
385
417
 
386
418
  performance.responseStart = Date.now()
387
- await handleResponse(api, response, performance)
419
+ await handleResponse({ api, componentData, res: response, performance })
388
420
  return
389
421
  } catch (error: any) {
390
422
  const body = error.cause
391
423
  ? { message: error.message, data: error.cause }
392
424
  : error.message
393
- apiError(api, { body }, { ...performance, responseEnd: Date.now() })
394
- triggerActions('failed', api, { body })
425
+ apiError({
426
+ api,
427
+ componentData,
428
+ data: { body },
429
+ performance: { ...performance, responseEnd: Date.now() },
430
+ })
431
+ triggerActions({
432
+ eventName: 'failed',
433
+ api,
434
+ data: { body },
435
+ componentData,
436
+ })
395
437
  return Promise.reject(error)
396
438
  }
397
439
  }
@@ -406,7 +448,10 @@ export function createAPI(
406
448
  () => {
407
449
  run().then(resolve, reject)
408
450
  },
409
- applyFormula(api.client?.debounce?.formula, getFormulaContext(api)),
451
+ applyFormula(
452
+ api.client?.debounce?.formula,
453
+ getFormulaContext(api, componentData),
454
+ ),
410
455
  )
411
456
  })
412
457
  }
@@ -414,11 +459,17 @@ export function createAPI(
414
459
  return run()
415
460
  }
416
461
 
417
- function handleResponse(
418
- api: ApiRequest,
419
- res: Response,
420
- performance: ApiPerformance,
421
- ) {
462
+ function handleResponse({
463
+ api,
464
+ componentData,
465
+ res,
466
+ performance,
467
+ }: {
468
+ api: ApiRequest
469
+ componentData: ComponentData
470
+ res: Response
471
+ performance: ApiPerformance
472
+ }) {
422
473
  let parserMode = api.client?.parserMode ?? 'auto'
423
474
 
424
475
  if (parserMode === 'auto') {
@@ -440,25 +491,31 @@ export function createAPI(
440
491
 
441
492
  switch (parserMode) {
442
493
  case 'text':
443
- return textStreamResponse(api, res, performance)
494
+ return textStreamResponse({ api, componentData, res, performance })
444
495
  case 'json':
445
- return jsonResponse(api, res, performance)
496
+ return jsonResponse({ api, componentData, res, performance })
446
497
  case 'event-stream':
447
- return eventStreamingResponse(api, res, performance)
498
+ return eventStreamingResponse({ api, componentData, res, performance })
448
499
  case 'json-stream':
449
- return jsonStreamResponse(api, res, performance)
500
+ return jsonStreamResponse({ api, componentData, res, performance })
450
501
  case 'blob':
451
- return blobResponse(api, res, performance)
502
+ return blobResponse({ api, componentData, res, performance })
452
503
  default:
453
- return textStreamResponse(api, res, performance)
504
+ return textStreamResponse({ api, componentData, res, performance })
454
505
  }
455
506
  }
456
507
 
457
- function textStreamResponse(
458
- api: ApiRequest,
459
- res: Response,
460
- performance: ApiPerformance,
461
- ) {
508
+ function textStreamResponse({
509
+ api,
510
+ res,
511
+ performance,
512
+ componentData,
513
+ }: {
514
+ api: ApiRequest
515
+ res: Response
516
+ performance: ApiPerformance
517
+ componentData: ComponentData
518
+ }) {
462
519
  return handleStreaming({
463
520
  api,
464
521
  res,
@@ -467,14 +524,21 @@ export function createAPI(
467
524
  useTextDecoder: true,
468
525
  parseChunk: (chunk) => chunk,
469
526
  parseChunksForData: (chunks) => chunks.join(''),
527
+ componentData,
470
528
  })
471
529
  }
472
530
 
473
- function jsonStreamResponse(
474
- api: ApiRequest,
475
- res: Response,
476
- performance: ApiPerformance,
477
- ) {
531
+ function jsonStreamResponse({
532
+ api,
533
+ res,
534
+ performance,
535
+ componentData,
536
+ }: {
537
+ api: ApiRequest
538
+ res: Response
539
+ performance: ApiPerformance
540
+ componentData: ComponentData
541
+ }) {
478
542
  const parseChunk = (chunk: any) => {
479
543
  let parsedData = chunk
480
544
  try {
@@ -496,14 +560,21 @@ export function createAPI(
496
560
  parseChunk,
497
561
  parseChunksForData: (chunks) => [...chunks],
498
562
  delimiters: ['\r\n', '\n'],
563
+ componentData,
499
564
  })
500
565
  }
501
566
 
502
- async function jsonResponse(
503
- api: ApiRequest,
504
- res: Response,
505
- performance: ApiPerformance,
506
- ) {
567
+ async function jsonResponse({
568
+ api,
569
+ componentData,
570
+ res,
571
+ performance,
572
+ }: {
573
+ api: ApiRequest
574
+ componentData: ComponentData
575
+ res: Response
576
+ performance: ApiPerformance
577
+ }) {
507
578
  const body = await res.json()
508
579
 
509
580
  const status: ApiStatus = {
@@ -515,14 +586,20 @@ export function createAPI(
515
586
  headers: Object.fromEntries(res.headers.entries()),
516
587
  },
517
588
  }
518
- return endResponse(api, status, performance)
589
+ return endResponse({ api, apiStatus: status, componentData, performance })
519
590
  }
520
591
 
521
- async function blobResponse(
522
- api: ApiRequest,
523
- res: Response,
524
- performance: ApiPerformance,
525
- ) {
592
+ async function blobResponse({
593
+ api,
594
+ componentData,
595
+ res,
596
+ performance,
597
+ }: {
598
+ api: ApiRequest
599
+ componentData: ComponentData
600
+ res: Response
601
+ performance: ApiPerformance
602
+ }) {
526
603
  const blob = await res.blob()
527
604
 
528
605
  const status: ApiStatus = {
@@ -534,14 +611,20 @@ export function createAPI(
534
611
  headers: Object.fromEntries(res.headers.entries()),
535
612
  },
536
613
  }
537
- return endResponse(api, status, performance)
614
+ return endResponse({ api, apiStatus: status, componentData, performance })
538
615
  }
539
616
 
540
- function eventStreamingResponse(
541
- api: ApiRequest,
542
- res: Response,
543
- performance: ApiPerformance,
544
- ) {
617
+ function eventStreamingResponse({
618
+ api,
619
+ res,
620
+ performance,
621
+ componentData,
622
+ }: {
623
+ api: ApiRequest
624
+ res: Response
625
+ performance: ApiPerformance
626
+ componentData: ComponentData
627
+ }) {
545
628
  const parseChunk = (chunk: string) => {
546
629
  const event = chunk.match(/event: (.*)/)?.[1] ?? 'message'
547
630
  const data = chunk.match(/data: (.*)/)?.[1] ?? ''
@@ -570,6 +653,7 @@ export function createAPI(
570
653
  parseChunk,
571
654
  parseChunksForData: (chunks) => [...chunks],
572
655
  delimiters: ['\n\n', '\r\n\r\n'],
656
+ componentData,
573
657
  })
574
658
  }
575
659
 
@@ -581,7 +665,8 @@ export function createAPI(
581
665
  useTextDecoder,
582
666
  parseChunk,
583
667
  parseChunksForData,
584
- delimiters, // There can be various delimiters for the same stream. SSE might use both \n\n and \r\n\r\n
668
+ delimiters, // There can be various delimiters for the same stream. SSE might use both \n\n and \r\n\r\n,
669
+ componentData,
585
670
  }: {
586
671
  api: ApiRequest
587
672
  res: Response
@@ -591,6 +676,7 @@ export function createAPI(
591
676
  parseChunk: (chunk: any) => any
592
677
  parseChunksForData: (chunks: any[]) => any
593
678
  delimiters?: string[]
679
+ componentData: ComponentData
594
680
  }) {
595
681
  const chunks: {
596
682
  chunks: any[]
@@ -621,7 +707,12 @@ export function createAPI(
621
707
  },
622
708
  })
623
709
  if ((api.client?.onMessage?.actions ?? []).length > 0) {
624
- triggerActions('message', api, { body: parsedChunk })
710
+ triggerActions({
711
+ eventName: 'message',
712
+ api,
713
+ data: { body: parsedChunk },
714
+ componentData,
715
+ })
625
716
  }
626
717
  }
627
718
  },
@@ -680,14 +771,20 @@ export function createAPI(
680
771
  cause: chunks.chunks.join(''),
681
772
  })
682
773
  }
683
- return endResponse(api, status, performance)
774
+ return endResponse({ api, apiStatus: status, componentData, performance })
684
775
  }
685
776
 
686
- function endResponse(
687
- api: ApiRequest,
688
- apiStatus: ApiStatus,
689
- performance: ApiPerformance,
690
- ) {
777
+ function endResponse({
778
+ api,
779
+ apiStatus,
780
+ componentData,
781
+ performance,
782
+ }: {
783
+ api: ApiRequest
784
+ apiStatus: ApiStatus
785
+ componentData: ComponentData
786
+ performance: ApiPerformance
787
+ }) {
691
788
  performance.responseEnd = Date.now()
692
789
 
693
790
  const data = {
@@ -708,7 +805,7 @@ export function createAPI(
708
805
  status: data.status,
709
806
  headers: data.headers,
710
807
  },
711
- formulaContext: getFormulaContext(api),
808
+ formulaContext: getFormulaContext(api, componentData),
712
809
  errorFormula: api.isError,
713
810
  performance,
714
811
  })
@@ -718,11 +815,11 @@ export function createAPI(
718
815
  data.body = apiStatus.error
719
816
  }
720
817
 
721
- apiError(api, data, performance)
722
- triggerActions('failed', api, data)
818
+ apiError({ api, componentData, data, performance })
819
+ triggerActions({ eventName: 'failed', api, componentData, data })
723
820
  } else {
724
- apiSuccess(api, data, performance)
725
- triggerActions('success', api, data)
821
+ apiSuccess({ api, componentData, data, performance })
822
+ triggerActions({ eventName: 'success', api, componentData, data })
726
823
  }
727
824
  }
728
825
 
@@ -757,9 +854,9 @@ export function createAPI(
757
854
 
758
855
  // eslint-disable-next-line prefer-const
759
856
  payloadSignal = ctx.dataSignal.map((_) => {
760
- const payloadContext = getFormulaContext(api)
857
+ const payloadContext = getFormulaContext(api, initialComponentData)
761
858
  return {
762
- request: constructRequest(api),
859
+ request: constructRequest(api, initialComponentData),
763
860
  api: getApiForComparison(api),
764
861
  autoFetch: api.autoFetch
765
862
  ? applyFormula(api.autoFetch, payloadContext)
@@ -768,7 +865,7 @@ export function createAPI(
768
865
  }
769
866
  })
770
867
  payloadSignal.subscribe(async (_) => {
771
- const { url, requestSettings } = constructRequest(api)
868
+ const { url, requestSettings } = constructRequest(api, initialComponentData)
772
869
  // Ensure we only use caching if the page is currently loading
773
870
  const cacheMatch =
774
871
  // We lookup the API from cache as long as autofetch is defined (and not statically falsy)
@@ -783,42 +880,54 @@ export function createAPI(
783
880
 
784
881
  if (cacheMatch) {
785
882
  if (cacheMatch.error) {
786
- apiError(
883
+ apiError({
787
884
  api,
788
- {
885
+ data: {
789
886
  body: cacheMatch.error,
790
887
  status: cacheMatch.response?.status,
791
888
  headers: cacheMatch.response?.headers ?? undefined,
792
889
  },
793
- {
890
+ performance: {
794
891
  requestStart:
795
892
  cacheMatch.response?.performance?.requestStart ?? null,
796
893
  responseStart:
797
894
  cacheMatch.response?.performance?.responseStart ?? null,
798
895
  responseEnd: cacheMatch.response?.performance?.responseEnd ?? null,
799
896
  },
800
- )
897
+ componentData: initialComponentData,
898
+ })
801
899
  } else {
802
- apiSuccess(
900
+ apiSuccess({
803
901
  api,
804
- {
902
+ data: {
805
903
  body: cacheMatch.data,
806
904
  status: cacheMatch.response?.status,
807
905
  headers: cacheMatch.response?.headers ?? undefined,
808
906
  },
809
- {
907
+ performance: {
810
908
  requestStart:
811
909
  cacheMatch.response?.performance?.requestStart ?? null,
812
910
  responseStart:
813
911
  cacheMatch.response?.performance?.responseStart ?? null,
814
912
  responseEnd: cacheMatch.response?.performance?.responseEnd ?? null,
815
913
  },
816
- )
914
+ componentData: initialComponentData,
915
+ })
817
916
  }
818
917
  } else {
819
- if (applyFormula(api.autoFetch, getFormulaContext(api))) {
918
+ if (
919
+ applyFormula(
920
+ api.autoFetch,
921
+ getFormulaContext(api, initialComponentData),
922
+ )
923
+ ) {
820
924
  // Execute will set the initial status of the api in the dataSignal
821
- await execute(api, url, requestSettings)
925
+ await execute({
926
+ api,
927
+ url,
928
+ requestSettings,
929
+ componentData: initialComponentData,
930
+ })
822
931
  } else {
823
932
  ctx.dataSignal.update((data) => {
824
933
  return {
@@ -838,24 +947,7 @@ export function createAPI(
838
947
  })
839
948
 
840
949
  return {
841
- fetch: ({
842
- actionInputs,
843
- actionModels,
844
- }: {
845
- actionInputs?: Record<
846
- string,
847
- | ValueOperationValue
848
- | {
849
- name: string
850
- formula?: Formula
851
- }
852
- >
853
- actionModels?: {
854
- onCompleted: ActionModel[]
855
- onFailed: ActionModel[]
856
- onMessage: ActionModel[]
857
- }
858
- }) => {
950
+ fetch: ({ actionInputs, actionModels, componentData }) => {
859
951
  // Inputs might already be evaluated. If they are we add them as a value formula to be evaluated later.
860
952
  const inputs = Object.entries(actionInputs ?? {}).reduce<
861
953
  Record<
@@ -907,18 +999,26 @@ export function createAPI(
907
999
  },
908
1000
  }
909
1001
 
910
- const { url, requestSettings } = constructRequest(apiWithInputsAndActions)
1002
+ const { url, requestSettings } = constructRequest(
1003
+ apiWithInputsAndActions,
1004
+ componentData,
1005
+ )
911
1006
 
912
- return execute(apiWithInputsAndActions, url, requestSettings)
1007
+ return execute({
1008
+ api: apiWithInputsAndActions,
1009
+ url,
1010
+ requestSettings,
1011
+ componentData,
1012
+ })
913
1013
  },
914
- update: (newApi: ApiRequest) => {
1014
+ update: (newApi, componentData) => {
915
1015
  api = newApi
916
- const updateContext = getFormulaContext(api)
1016
+ const updateContext = getFormulaContext(api, componentData)
917
1017
  const autoFetch =
918
1018
  api.autoFetch && applyFormula(api.autoFetch, updateContext)
919
1019
  if (autoFetch) {
920
1020
  payloadSignal?.set({
921
- request: constructRequest(newApi),
1021
+ request: constructRequest(newApi, componentData),
922
1022
  api: getApiForComparison(newApi),
923
1023
  autoFetch,
924
1024
  proxy: applyFormula(
@@ -928,7 +1028,7 @@ export function createAPI(
928
1028
  })
929
1029
  }
930
1030
  },
931
- triggerActions: () => {
1031
+ triggerActions: (componentData) => {
932
1032
  const apiData = ctx.dataSignal.get().Apis?.[api.name]
933
1033
  if (
934
1034
  apiData === undefined ||
@@ -937,13 +1037,23 @@ export function createAPI(
937
1037
  return
938
1038
  }
939
1039
  if (apiData.error) {
940
- triggerActions('failed', api, {
941
- body: apiData.error,
942
- status: apiData.response?.status,
1040
+ triggerActions({
1041
+ eventName: 'failed',
1042
+ api,
1043
+ data: {
1044
+ body: apiData.error,
1045
+ status: apiData.response?.status,
1046
+ },
1047
+ componentData,
943
1048
  })
944
1049
  } else {
945
- triggerActions('success', api, {
946
- body: apiData.data,
1050
+ triggerActions({
1051
+ eventName: 'success',
1052
+ api,
1053
+ data: {
1054
+ body: apiData.data,
1055
+ },
1056
+ componentData,
947
1057
  })
948
1058
  }
949
1059
  },