astro-tractstack 2.0.40 → 2.0.41
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/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
2
|
import { transformLivePaneForPreview } from '@/utils/etl';
|
|
3
3
|
import type { NodesContext } from '@/stores/nodes';
|
|
4
|
+
import { TractStackAPI } from '@/utils/api';
|
|
4
5
|
|
|
5
6
|
export interface PanePreviewRequest {
|
|
6
7
|
id: string;
|
|
@@ -67,27 +68,22 @@ export const PanesPreviewGenerator = ({
|
|
|
67
68
|
requestMap.set(previewPayload.id, request.id);
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
method: 'POST',
|
|
74
|
-
headers: {
|
|
75
|
-
'Content-Type': 'application/json',
|
|
76
|
-
'X-Tenant-ID': import.meta.env.PUBLIC_TENANTID || 'default',
|
|
77
|
-
},
|
|
78
|
-
body: JSON.stringify({ panes: previewPayloads }),
|
|
71
|
+
const api = new TractStackAPI();
|
|
72
|
+
const response = await api.post('/api/v1/fragments/preview', {
|
|
73
|
+
panes: previewPayloads,
|
|
79
74
|
});
|
|
80
75
|
|
|
81
|
-
if (!response.
|
|
82
|
-
throw new Error(`Preview API failed
|
|
76
|
+
if (!response.success) {
|
|
77
|
+
throw new Error(response.error || `Preview API failed`);
|
|
83
78
|
}
|
|
84
79
|
|
|
85
|
-
|
|
80
|
+
// TractStackAPI unwraps the response.data for us
|
|
81
|
+
const { fragments, errors } = response.data;
|
|
86
82
|
|
|
87
83
|
const results: PaneFragmentResult[] = [];
|
|
88
84
|
|
|
89
85
|
for (const [paneId, requestId] of requestMap.entries()) {
|
|
90
|
-
if (fragments[paneId]) {
|
|
86
|
+
if (fragments && fragments[paneId]) {
|
|
91
87
|
results.push({
|
|
92
88
|
id: requestId,
|
|
93
89
|
htmlString: fragments[paneId],
|