@nordcraft/runtime 1.0.49 → 1.0.50
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.
- package/dist/api/createAPIv2.js +104 -26
- package/dist/api/createAPIv2.js.map +1 -1
- package/dist/custom-element.main.esm.js +20 -20
- package/dist/custom-element.main.esm.js.map +4 -4
- package/dist/events/handleAction.js +6 -1
- package/dist/events/handleAction.js.map +1 -1
- package/dist/page.main.esm.js +3 -3
- package/dist/page.main.esm.js.map +4 -4
- package/package.json +3 -3
- package/src/api/createAPIv2.ts +119 -13
- package/src/events/handleAction.ts +6 -1
- package/src/types.d.ts +1 -0
package/package.json
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
"type": "module",
|
|
5
5
|
"homepage": "https://github.com/nordcraftengine/nordcraft",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@nordcraft/core": "1.0.
|
|
8
|
-
"@nordcraft/std-lib": "1.0.
|
|
7
|
+
"@nordcraft/core": "1.0.50",
|
|
8
|
+
"@nordcraft/std-lib": "1.0.50",
|
|
9
9
|
"fast-deep-equal": "3.1.3",
|
|
10
10
|
"path-to-regexp": "6.3.0"
|
|
11
11
|
},
|
|
@@ -21,5 +21,5 @@
|
|
|
21
21
|
"files": ["dist", "src"],
|
|
22
22
|
"main": "dist/page.main.js",
|
|
23
23
|
"types": "dist/page.main.d.ts",
|
|
24
|
-
"version": "1.0.
|
|
24
|
+
"version": "1.0.50"
|
|
25
25
|
}
|
package/src/api/createAPIv2.ts
CHANGED
|
@@ -174,6 +174,7 @@ export function createAPI({
|
|
|
174
174
|
api,
|
|
175
175
|
data,
|
|
176
176
|
componentData,
|
|
177
|
+
workflowCallback,
|
|
177
178
|
}: {
|
|
178
179
|
eventName: 'message' | 'success' | 'failed'
|
|
179
180
|
api: ApiRequest
|
|
@@ -183,6 +184,7 @@ export function createAPI({
|
|
|
183
184
|
headers?: Record<string, string>
|
|
184
185
|
}
|
|
185
186
|
componentData: ComponentData
|
|
187
|
+
workflowCallback?: (event: string, data: unknown) => void
|
|
186
188
|
}) {
|
|
187
189
|
switch (eventName) {
|
|
188
190
|
case 'message': {
|
|
@@ -196,6 +198,7 @@ export function createAPI({
|
|
|
196
198
|
},
|
|
197
199
|
ctx,
|
|
198
200
|
event,
|
|
201
|
+
workflowCallback,
|
|
199
202
|
)
|
|
200
203
|
})
|
|
201
204
|
break
|
|
@@ -211,6 +214,7 @@ export function createAPI({
|
|
|
211
214
|
},
|
|
212
215
|
ctx,
|
|
213
216
|
event,
|
|
217
|
+
workflowCallback,
|
|
214
218
|
)
|
|
215
219
|
})
|
|
216
220
|
break
|
|
@@ -229,6 +233,7 @@ export function createAPI({
|
|
|
229
233
|
},
|
|
230
234
|
ctx,
|
|
231
235
|
event,
|
|
236
|
+
workflowCallback,
|
|
232
237
|
)
|
|
233
238
|
})
|
|
234
239
|
break
|
|
@@ -369,11 +374,13 @@ export function createAPI({
|
|
|
369
374
|
url,
|
|
370
375
|
requestSettings,
|
|
371
376
|
componentData,
|
|
377
|
+
workflowCallback,
|
|
372
378
|
}: {
|
|
373
379
|
api: ApiRequest
|
|
374
380
|
url: URL
|
|
375
381
|
requestSettings: ToddleRequestInit
|
|
376
382
|
componentData: ComponentData
|
|
383
|
+
workflowCallback?: (event: string, data: unknown) => void
|
|
377
384
|
}) {
|
|
378
385
|
const run = async () => {
|
|
379
386
|
const performance: ApiPerformance = {
|
|
@@ -429,7 +436,13 @@ export function createAPI({
|
|
|
429
436
|
}
|
|
430
437
|
|
|
431
438
|
performance.responseStart = Date.now()
|
|
432
|
-
await handleResponse({
|
|
439
|
+
await handleResponse({
|
|
440
|
+
api,
|
|
441
|
+
componentData,
|
|
442
|
+
res: response,
|
|
443
|
+
performance,
|
|
444
|
+
workflowCallback,
|
|
445
|
+
})
|
|
433
446
|
return
|
|
434
447
|
} catch (error: any) {
|
|
435
448
|
const body = error.cause
|
|
@@ -446,6 +459,7 @@ export function createAPI({
|
|
|
446
459
|
api,
|
|
447
460
|
data: { body },
|
|
448
461
|
componentData,
|
|
462
|
+
workflowCallback,
|
|
449
463
|
})
|
|
450
464
|
return Promise.reject(error)
|
|
451
465
|
}
|
|
@@ -477,11 +491,13 @@ export function createAPI({
|
|
|
477
491
|
componentData,
|
|
478
492
|
res,
|
|
479
493
|
performance,
|
|
494
|
+
workflowCallback,
|
|
480
495
|
}: {
|
|
481
496
|
api: ApiRequest
|
|
482
497
|
componentData: ComponentData
|
|
483
498
|
res: Response
|
|
484
499
|
performance: ApiPerformance
|
|
500
|
+
workflowCallback?: (event: string, data: unknown) => void
|
|
485
501
|
}) {
|
|
486
502
|
let parserMode = api.client?.parserMode ?? 'auto'
|
|
487
503
|
|
|
@@ -504,17 +520,53 @@ export function createAPI({
|
|
|
504
520
|
|
|
505
521
|
switch (parserMode) {
|
|
506
522
|
case 'text':
|
|
507
|
-
return textStreamResponse({
|
|
523
|
+
return textStreamResponse({
|
|
524
|
+
api,
|
|
525
|
+
componentData,
|
|
526
|
+
res,
|
|
527
|
+
performance,
|
|
528
|
+
workflowCallback,
|
|
529
|
+
})
|
|
508
530
|
case 'json':
|
|
509
|
-
return jsonResponse({
|
|
531
|
+
return jsonResponse({
|
|
532
|
+
api,
|
|
533
|
+
componentData,
|
|
534
|
+
res,
|
|
535
|
+
performance,
|
|
536
|
+
workflowCallback,
|
|
537
|
+
})
|
|
510
538
|
case 'event-stream':
|
|
511
|
-
return eventStreamingResponse({
|
|
539
|
+
return eventStreamingResponse({
|
|
540
|
+
api,
|
|
541
|
+
componentData,
|
|
542
|
+
res,
|
|
543
|
+
performance,
|
|
544
|
+
workflowCallback,
|
|
545
|
+
})
|
|
512
546
|
case 'json-stream':
|
|
513
|
-
return jsonStreamResponse({
|
|
547
|
+
return jsonStreamResponse({
|
|
548
|
+
api,
|
|
549
|
+
componentData,
|
|
550
|
+
res,
|
|
551
|
+
performance,
|
|
552
|
+
workflowCallback,
|
|
553
|
+
})
|
|
514
554
|
case 'blob':
|
|
515
|
-
return blobResponse({
|
|
555
|
+
return blobResponse({
|
|
556
|
+
api,
|
|
557
|
+
componentData,
|
|
558
|
+
res,
|
|
559
|
+
performance,
|
|
560
|
+
workflowCallback,
|
|
561
|
+
})
|
|
516
562
|
default:
|
|
517
|
-
return textStreamResponse({
|
|
563
|
+
return textStreamResponse({
|
|
564
|
+
api,
|
|
565
|
+
componentData,
|
|
566
|
+
res,
|
|
567
|
+
performance,
|
|
568
|
+
workflowCallback,
|
|
569
|
+
})
|
|
518
570
|
}
|
|
519
571
|
}
|
|
520
572
|
|
|
@@ -523,11 +575,13 @@ export function createAPI({
|
|
|
523
575
|
res,
|
|
524
576
|
performance,
|
|
525
577
|
componentData,
|
|
578
|
+
workflowCallback,
|
|
526
579
|
}: {
|
|
527
580
|
api: ApiRequest
|
|
528
581
|
res: Response
|
|
529
582
|
performance: ApiPerformance
|
|
530
583
|
componentData: ComponentData
|
|
584
|
+
workflowCallback?: (event: string, data: unknown) => void
|
|
531
585
|
}) {
|
|
532
586
|
return handleStreaming({
|
|
533
587
|
api,
|
|
@@ -538,6 +592,7 @@ export function createAPI({
|
|
|
538
592
|
parseChunk: (chunk) => chunk,
|
|
539
593
|
parseChunksForData: (chunks) => chunks.join(''),
|
|
540
594
|
componentData,
|
|
595
|
+
workflowCallback,
|
|
541
596
|
})
|
|
542
597
|
}
|
|
543
598
|
|
|
@@ -546,11 +601,13 @@ export function createAPI({
|
|
|
546
601
|
res,
|
|
547
602
|
performance,
|
|
548
603
|
componentData,
|
|
604
|
+
workflowCallback,
|
|
549
605
|
}: {
|
|
550
606
|
api: ApiRequest
|
|
551
607
|
res: Response
|
|
552
608
|
performance: ApiPerformance
|
|
553
609
|
componentData: ComponentData
|
|
610
|
+
workflowCallback?: (event: string, data: unknown) => void
|
|
554
611
|
}) {
|
|
555
612
|
const parseChunk = (chunk: any) => {
|
|
556
613
|
let parsedData = chunk
|
|
@@ -574,6 +631,7 @@ export function createAPI({
|
|
|
574
631
|
parseChunksForData: (chunks) => [...chunks],
|
|
575
632
|
delimiters: ['\r\n', '\n'],
|
|
576
633
|
componentData,
|
|
634
|
+
workflowCallback,
|
|
577
635
|
})
|
|
578
636
|
}
|
|
579
637
|
|
|
@@ -582,11 +640,13 @@ export function createAPI({
|
|
|
582
640
|
componentData,
|
|
583
641
|
res,
|
|
584
642
|
performance,
|
|
643
|
+
workflowCallback,
|
|
585
644
|
}: {
|
|
586
645
|
api: ApiRequest
|
|
587
646
|
componentData: ComponentData
|
|
588
647
|
res: Response
|
|
589
648
|
performance: ApiPerformance
|
|
649
|
+
workflowCallback?: (event: string, data: unknown) => void
|
|
590
650
|
}) {
|
|
591
651
|
const body = await res.json()
|
|
592
652
|
|
|
@@ -599,7 +659,13 @@ export function createAPI({
|
|
|
599
659
|
headers: mapHeadersToObject(res.headers),
|
|
600
660
|
},
|
|
601
661
|
}
|
|
602
|
-
return endResponse({
|
|
662
|
+
return endResponse({
|
|
663
|
+
api,
|
|
664
|
+
apiStatus: status,
|
|
665
|
+
componentData,
|
|
666
|
+
performance,
|
|
667
|
+
workflowCallback,
|
|
668
|
+
})
|
|
603
669
|
}
|
|
604
670
|
|
|
605
671
|
async function blobResponse({
|
|
@@ -607,11 +673,13 @@ export function createAPI({
|
|
|
607
673
|
componentData,
|
|
608
674
|
res,
|
|
609
675
|
performance,
|
|
676
|
+
workflowCallback,
|
|
610
677
|
}: {
|
|
611
678
|
api: ApiRequest
|
|
612
679
|
componentData: ComponentData
|
|
613
680
|
res: Response
|
|
614
681
|
performance: ApiPerformance
|
|
682
|
+
workflowCallback?: (event: string, data: unknown) => void
|
|
615
683
|
}) {
|
|
616
684
|
const blob = await res.blob()
|
|
617
685
|
|
|
@@ -624,7 +692,13 @@ export function createAPI({
|
|
|
624
692
|
headers: mapHeadersToObject(res.headers),
|
|
625
693
|
},
|
|
626
694
|
}
|
|
627
|
-
return endResponse({
|
|
695
|
+
return endResponse({
|
|
696
|
+
api,
|
|
697
|
+
apiStatus: status,
|
|
698
|
+
componentData,
|
|
699
|
+
performance,
|
|
700
|
+
workflowCallback,
|
|
701
|
+
})
|
|
628
702
|
}
|
|
629
703
|
|
|
630
704
|
function eventStreamingResponse({
|
|
@@ -632,11 +706,13 @@ export function createAPI({
|
|
|
632
706
|
res,
|
|
633
707
|
performance,
|
|
634
708
|
componentData,
|
|
709
|
+
workflowCallback,
|
|
635
710
|
}: {
|
|
636
711
|
api: ApiRequest
|
|
637
712
|
res: Response
|
|
638
713
|
performance: ApiPerformance
|
|
639
714
|
componentData: ComponentData
|
|
715
|
+
workflowCallback?: (event: string, data: unknown) => void
|
|
640
716
|
}) {
|
|
641
717
|
const parseChunk = (chunk: string) => {
|
|
642
718
|
const event = chunk.match(/event: (.*)/)?.[1] ?? 'message'
|
|
@@ -667,6 +743,7 @@ export function createAPI({
|
|
|
667
743
|
parseChunksForData: (chunks) => [...chunks],
|
|
668
744
|
delimiters: ['\n\n', '\r\n\r\n'],
|
|
669
745
|
componentData,
|
|
746
|
+
workflowCallback,
|
|
670
747
|
})
|
|
671
748
|
}
|
|
672
749
|
|
|
@@ -680,6 +757,7 @@ export function createAPI({
|
|
|
680
757
|
parseChunksForData,
|
|
681
758
|
delimiters, // There can be various delimiters for the same stream. SSE might use both \n\n and \r\n\r\n,
|
|
682
759
|
componentData,
|
|
760
|
+
workflowCallback,
|
|
683
761
|
}: {
|
|
684
762
|
api: ApiRequest
|
|
685
763
|
res: Response
|
|
@@ -690,6 +768,7 @@ export function createAPI({
|
|
|
690
768
|
parseChunksForData: (chunks: any[]) => any
|
|
691
769
|
delimiters?: string[]
|
|
692
770
|
componentData: ComponentData
|
|
771
|
+
workflowCallback?: (event: string, data: unknown) => void
|
|
693
772
|
}) {
|
|
694
773
|
const chunks: {
|
|
695
774
|
chunks: any[]
|
|
@@ -725,6 +804,7 @@ export function createAPI({
|
|
|
725
804
|
api,
|
|
726
805
|
data: { body: parsedChunk },
|
|
727
806
|
componentData,
|
|
807
|
+
workflowCallback,
|
|
728
808
|
})
|
|
729
809
|
}
|
|
730
810
|
}
|
|
@@ -784,7 +864,13 @@ export function createAPI({
|
|
|
784
864
|
cause: chunks.chunks.join(''),
|
|
785
865
|
})
|
|
786
866
|
}
|
|
787
|
-
return endResponse({
|
|
867
|
+
return endResponse({
|
|
868
|
+
api,
|
|
869
|
+
apiStatus: status,
|
|
870
|
+
componentData,
|
|
871
|
+
performance,
|
|
872
|
+
workflowCallback,
|
|
873
|
+
})
|
|
788
874
|
}
|
|
789
875
|
|
|
790
876
|
function endResponse({
|
|
@@ -792,11 +878,13 @@ export function createAPI({
|
|
|
792
878
|
apiStatus,
|
|
793
879
|
componentData,
|
|
794
880
|
performance,
|
|
881
|
+
workflowCallback,
|
|
795
882
|
}: {
|
|
796
883
|
api: ApiRequest
|
|
797
884
|
apiStatus: ApiStatus
|
|
798
885
|
componentData: ComponentData
|
|
799
886
|
performance: ApiPerformance
|
|
887
|
+
workflowCallback?: (event: string, data: unknown) => void
|
|
800
888
|
}) {
|
|
801
889
|
performance.responseEnd = Date.now()
|
|
802
890
|
|
|
@@ -829,10 +917,22 @@ export function createAPI({
|
|
|
829
917
|
}
|
|
830
918
|
|
|
831
919
|
apiError({ api, componentData, data, performance })
|
|
832
|
-
triggerActions({
|
|
920
|
+
triggerActions({
|
|
921
|
+
eventName: 'failed',
|
|
922
|
+
api,
|
|
923
|
+
componentData,
|
|
924
|
+
data,
|
|
925
|
+
workflowCallback,
|
|
926
|
+
})
|
|
833
927
|
} else {
|
|
834
928
|
apiSuccess({ api, componentData, data, performance })
|
|
835
|
-
triggerActions({
|
|
929
|
+
triggerActions({
|
|
930
|
+
eventName: 'success',
|
|
931
|
+
api,
|
|
932
|
+
componentData,
|
|
933
|
+
data,
|
|
934
|
+
workflowCallback,
|
|
935
|
+
})
|
|
836
936
|
}
|
|
837
937
|
}
|
|
838
938
|
|
|
@@ -962,7 +1062,12 @@ export function createAPI({
|
|
|
962
1062
|
})
|
|
963
1063
|
|
|
964
1064
|
return {
|
|
965
|
-
fetch: ({
|
|
1065
|
+
fetch: ({
|
|
1066
|
+
actionInputs,
|
|
1067
|
+
actionModels,
|
|
1068
|
+
componentData,
|
|
1069
|
+
workflowCallback,
|
|
1070
|
+
}) => {
|
|
966
1071
|
// Inputs might already be evaluated. If they are we add them as a value formula to be evaluated later.
|
|
967
1072
|
const inputs = Object.entries(actionInputs ?? {}).reduce<
|
|
968
1073
|
Record<
|
|
@@ -1024,6 +1129,7 @@ export function createAPI({
|
|
|
1024
1129
|
url,
|
|
1025
1130
|
requestSettings,
|
|
1026
1131
|
componentData,
|
|
1132
|
+
workflowCallback,
|
|
1027
1133
|
})
|
|
1028
1134
|
},
|
|
1029
1135
|
update: (newApi, componentData) => {
|
|
@@ -281,7 +281,12 @@ export function handleAction(
|
|
|
281
281
|
onFailed: action.onError?.actions ?? [],
|
|
282
282
|
onMessage: action.onMessage?.actions ?? [],
|
|
283
283
|
}
|
|
284
|
-
void api.fetch({
|
|
284
|
+
void api.fetch({
|
|
285
|
+
actionInputs,
|
|
286
|
+
actionModels,
|
|
287
|
+
componentData: data,
|
|
288
|
+
workflowCallback,
|
|
289
|
+
})
|
|
285
290
|
} else {
|
|
286
291
|
const triggerActions = (actions: ActionModel[]) => {
|
|
287
292
|
for (const subAction of actions) {
|
package/src/types.d.ts
CHANGED
|
@@ -107,6 +107,7 @@ export interface ContextApiV2 {
|
|
|
107
107
|
onMessage: ActionModel[]
|
|
108
108
|
}
|
|
109
109
|
componentData: ComponentData
|
|
110
|
+
workflowCallback?: (event: string, data: unknown) => void
|
|
110
111
|
}) => Promise<unknown>
|
|
111
112
|
destroy: Function
|
|
112
113
|
update: (newApi: CoreApiRequest, componentData: ComponentData) => void // for updating the dataSignal
|