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,6 @@
1
1
  {
2
2
  "name": "astro-tractstack",
3
- "version": "2.0.40",
3
+ "version": "2.0.41",
4
4
  "description": "Astro integration for TractStack - redeeming the web from boring experiences",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -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 goBackend =
71
- import.meta.env.PUBLIC_GO_BACKEND || 'http://localhost:8080';
72
- const response = await fetch(`${goBackend}/api/v1/fragments/preview`, {
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.ok) {
82
- throw new Error(`Preview API failed: ${response.status}`);
76
+ if (!response.success) {
77
+ throw new Error(response.error || `Preview API failed`);
83
78
  }
84
79
 
85
- const { fragments, errors } = await response.json();
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],