camox 0.36.3 → 0.39.0
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/core/editing/createEditableBlock.js +197 -231
- package/dist/features/preview/components/CreatePageModal.js +2 -9
- package/dist/features/preview/components/PageEditorSidebar.js +2 -2
- package/dist/features/preview/components/PreviewPanel.js +12 -36
- package/dist/features/preview/components/RightSidebar.js +37 -75
- package/dist/features/preview/previewStore.js +5 -59
- package/dist/features/vite/auth.js +52 -0
- package/dist/features/vite/definitionsSync.js +13 -12
- package/dist/features/vite/devAuthentication.js +188 -0
- package/dist/features/vite/vite.d.ts +1 -3
- package/dist/features/vite/vite.js +25 -43
- package/dist/lib/api-client-server.js +2 -1
- package/dist/studio.css +1 -1
- package/package.json +4 -6
- package/skills/camox/SKILL.md +17 -0
- package/skills/{camox-block/SKILL.md → camox/references/block-definitions.md} +2 -7
- package/skills/camox/references/cli-blocks.md +78 -0
- package/skills/camox/references/cli-common.md +48 -0
- package/skills/camox/references/cli-environments.md +37 -0
- package/skills/camox/references/cli-pages.md +53 -0
- package/skills/{camox-layout/SKILL.md → camox/references/layout-definitions.md} +2 -7
- package/dist/features/agent-chat/agent-chat-labels.js +0 -200
- package/dist/features/agent-chat/components/AgentChatSidebar.js +0 -172
- package/dist/features/agent-chat/components/AgentChatThread.js +0 -593
- package/dist/features/agent-chat/components/AgentToolCallCard.js +0 -141
- package/dist/features/vite/skillGeneration.js +0 -104
- package/skills/camox-cli/SKILL.md +0 -268
|
@@ -17,9 +17,9 @@ import { PanelContent } from "@camox/ui/panel";
|
|
|
17
17
|
//#region src/features/preview/components/PreviewPanel.tsx
|
|
18
18
|
const PreviewFrame = (t0) => {
|
|
19
19
|
const $ = c(9);
|
|
20
|
-
if ($[0] !== "
|
|
20
|
+
if ($[0] !== "31124ccadd6d884c2ef4e5d4a3da6a444089b4761872b2ecf0bc4a99c1c65a08") {
|
|
21
21
|
for (let $i = 0; $i < 9; $i += 1) $[$i] = Symbol.for("react.memo_cache_sentinel");
|
|
22
|
-
$[0] = "
|
|
22
|
+
$[0] = "31124ccadd6d884c2ef4e5d4a3da6a444089b4761872b2ecf0bc4a99c1c65a08";
|
|
23
23
|
}
|
|
24
24
|
const { children, style, className, onIframeReady } = t0;
|
|
25
25
|
let t1;
|
|
@@ -60,9 +60,9 @@ const PreviewFrame = (t0) => {
|
|
|
60
60
|
};
|
|
61
61
|
const KeyDownForwarder = () => {
|
|
62
62
|
const $ = c(5);
|
|
63
|
-
if ($[0] !== "
|
|
63
|
+
if ($[0] !== "31124ccadd6d884c2ef4e5d4a3da6a444089b4761872b2ecf0bc4a99c1c65a08") {
|
|
64
64
|
for (let $i = 0; $i < 5; $i += 1) $[$i] = Symbol.for("react.memo_cache_sentinel");
|
|
65
|
-
$[0] = "
|
|
65
|
+
$[0] = "31124ccadd6d884c2ef4e5d4a3da6a444089b4761872b2ecf0bc4a99c1c65a08";
|
|
66
66
|
}
|
|
67
67
|
const { window: iframeWindow } = useFrame();
|
|
68
68
|
const actions = useSelector(actionsStore, _temp);
|
|
@@ -113,9 +113,9 @@ const viewportClassName = {
|
|
|
113
113
|
};
|
|
114
114
|
const PreviewPanel = (t0) => {
|
|
115
115
|
const $ = c(8);
|
|
116
|
-
if ($[0] !== "
|
|
116
|
+
if ($[0] !== "31124ccadd6d884c2ef4e5d4a3da6a444089b4761872b2ecf0bc4a99c1c65a08") {
|
|
117
117
|
for (let $i = 0; $i < 8; $i += 1) $[$i] = Symbol.for("react.memo_cache_sentinel");
|
|
118
|
-
$[0] = "
|
|
118
|
+
$[0] = "31124ccadd6d884c2ef4e5d4a3da6a444089b4761872b2ecf0bc4a99c1c65a08";
|
|
119
119
|
}
|
|
120
120
|
const { children, toolbarProps } = t0;
|
|
121
121
|
useBlockActionsShortcuts();
|
|
@@ -128,7 +128,7 @@ const PreviewPanel = (t0) => {
|
|
|
128
128
|
t1 = [];
|
|
129
129
|
$[1] = t1;
|
|
130
130
|
} else t1 = $[1];
|
|
131
|
-
React.useEffect(
|
|
131
|
+
React.useEffect(_temp15, t1);
|
|
132
132
|
let t2;
|
|
133
133
|
if ($[2] !== children || $[3] !== iframeElement || $[4] !== isEditMode || $[5] !== toolbarProps || $[6] !== viewportMode) {
|
|
134
134
|
t2 = /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(PanelContent, {
|
|
@@ -225,19 +225,12 @@ function _temp12() {
|
|
|
225
225
|
return true;
|
|
226
226
|
}
|
|
227
227
|
function _temp13() {
|
|
228
|
-
const { isAgentChatSidebarOpen } = previewStore.getSnapshot().context;
|
|
229
|
-
previewStore.send({ type: isAgentChatSidebarOpen ? "closeAgentChatSidebar" : "openAgentChatSidebar" });
|
|
230
|
-
}
|
|
231
|
-
function _temp14() {
|
|
232
|
-
return true;
|
|
233
|
-
}
|
|
234
|
-
function _temp15() {
|
|
235
228
|
previewStore.send({ type: "clearSelection" });
|
|
236
229
|
}
|
|
237
|
-
function
|
|
230
|
+
function _temp14(a) {
|
|
238
231
|
return a.id;
|
|
239
232
|
}
|
|
240
|
-
function
|
|
233
|
+
function _temp15() {
|
|
241
234
|
const actions = [
|
|
242
235
|
{
|
|
243
236
|
id: "cycle-viewport-mode",
|
|
@@ -284,30 +277,13 @@ function _temp17() {
|
|
|
284
277
|
checkIfAvailable: _temp10,
|
|
285
278
|
execute: _temp11
|
|
286
279
|
},
|
|
287
|
-
{
|
|
288
|
-
id: "toggle-agent-chat",
|
|
289
|
-
label: "Toggle agent chat",
|
|
290
|
-
aliases: [
|
|
291
|
-
"AI chat",
|
|
292
|
-
"Assistant",
|
|
293
|
-
"Ask AI",
|
|
294
|
-
"Open chat"
|
|
295
|
-
],
|
|
296
|
-
groupLabel: "Preview",
|
|
297
|
-
checkIfAvailable: _temp12,
|
|
298
|
-
execute: _temp13,
|
|
299
|
-
shortcut: {
|
|
300
|
-
key: "i",
|
|
301
|
-
withAlt: true
|
|
302
|
-
}
|
|
303
|
-
},
|
|
304
280
|
{
|
|
305
281
|
id: "clear-selection",
|
|
306
282
|
label: "Clear selection",
|
|
307
283
|
aliases: ["Deselect", "Unselect"],
|
|
308
284
|
groupLabel: "Preview",
|
|
309
|
-
checkIfAvailable:
|
|
310
|
-
execute:
|
|
285
|
+
checkIfAvailable: _temp12,
|
|
286
|
+
execute: _temp13,
|
|
311
287
|
shortcut: { key: "Escape" }
|
|
312
288
|
}
|
|
313
289
|
];
|
|
@@ -318,7 +294,7 @@ function _temp17() {
|
|
|
318
294
|
return () => {
|
|
319
295
|
actionsStore.send({
|
|
320
296
|
type: "unregisterManyActions",
|
|
321
|
-
ids: actions.map(
|
|
297
|
+
ids: actions.map(_temp14)
|
|
322
298
|
});
|
|
323
299
|
};
|
|
324
300
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { previewStore, selectionBlockId } from "../previewStore.js";
|
|
2
|
-
import { AgentChatSidebar } from "../../agent-chat/components/AgentChatSidebar.js";
|
|
3
2
|
import { PageEditorSidebar } from "./PageEditorSidebar.js";
|
|
4
3
|
import { PageInfoSidebar } from "./PageInfoSidebar.js";
|
|
5
4
|
import { c } from "react/compiler-runtime";
|
|
@@ -7,101 +6,64 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
7
6
|
import { useSelector } from "@xstate/store-react";
|
|
8
7
|
|
|
9
8
|
//#region src/features/preview/components/RightSidebar.tsx
|
|
10
|
-
const getRightSidebarRoute = ({ pageId, selectedBlockId, isAgentChatSidebarOpen }) => {
|
|
11
|
-
if (isAgentChatSidebarOpen) return { type: "agent-chat" };
|
|
12
|
-
if (selectedBlockId == null) return {
|
|
13
|
-
type: "page-info",
|
|
14
|
-
pageId
|
|
15
|
-
};
|
|
16
|
-
return { type: "page-editor" };
|
|
17
|
-
};
|
|
18
9
|
const RightSidebar = (t0) => {
|
|
19
|
-
const $ = c(
|
|
20
|
-
if ($[0] !== "
|
|
21
|
-
for (let $i = 0; $i <
|
|
22
|
-
$[0] = "
|
|
10
|
+
const $ = c(12);
|
|
11
|
+
if ($[0] !== "b9589c1fea2c3efabdd9fae80871373106138216610ee3b8e2f4045e3b45670f") {
|
|
12
|
+
for (let $i = 0; $i < 12; $i += 1) $[$i] = Symbol.for("react.memo_cache_sentinel");
|
|
13
|
+
$[0] = "b9589c1fea2c3efabdd9fae80871373106138216610ee3b8e2f4045e3b45670f";
|
|
23
14
|
}
|
|
24
15
|
const { pageId } = t0;
|
|
25
16
|
const selection = useSelector(previewStore, _temp);
|
|
26
|
-
const
|
|
27
|
-
const isAddBlockSidebarOpen = useSelector(previewStore, _temp3);
|
|
17
|
+
const isAddBlockSidebarOpen = useSelector(previewStore, _temp2);
|
|
28
18
|
let t1;
|
|
29
|
-
if ($[1] !==
|
|
30
|
-
t1 =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
$[1] = isAgentChatSidebarOpen;
|
|
36
|
-
$[2] = pageId;
|
|
37
|
-
$[3] = selection;
|
|
38
|
-
$[4] = t1;
|
|
39
|
-
} else t1 = $[4];
|
|
40
|
-
const route = t1;
|
|
19
|
+
if ($[1] !== selection) {
|
|
20
|
+
t1 = selectionBlockId(selection);
|
|
21
|
+
$[1] = selection;
|
|
22
|
+
$[2] = t1;
|
|
23
|
+
} else t1 = $[2];
|
|
24
|
+
const selectedBlockId = t1;
|
|
41
25
|
let t2;
|
|
42
|
-
if ($[
|
|
26
|
+
if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
|
|
43
27
|
t2 = { width: 250 };
|
|
44
|
-
$[
|
|
45
|
-
} else t2 = $[
|
|
28
|
+
$[3] = t2;
|
|
29
|
+
} else t2 = $[3];
|
|
46
30
|
let t3;
|
|
47
|
-
if ($[
|
|
48
|
-
t3 =
|
|
49
|
-
$[
|
|
50
|
-
$[
|
|
51
|
-
|
|
31
|
+
if ($[4] !== pageId || $[5] !== selectedBlockId) {
|
|
32
|
+
t3 = selectedBlockId == null ? /* @__PURE__ */ jsx(PageInfoSidebar, { pageId }) : /* @__PURE__ */ jsx(PageEditorSidebar, {});
|
|
33
|
+
$[4] = pageId;
|
|
34
|
+
$[5] = selectedBlockId;
|
|
35
|
+
$[6] = t3;
|
|
36
|
+
} else t3 = $[6];
|
|
52
37
|
let t4;
|
|
53
|
-
if ($[
|
|
54
|
-
t4 =
|
|
55
|
-
$[8] = route.pageId;
|
|
56
|
-
$[9] = route.type;
|
|
57
|
-
$[10] = t4;
|
|
58
|
-
} else t4 = $[10];
|
|
59
|
-
let t5;
|
|
60
|
-
if ($[11] !== route.type) {
|
|
61
|
-
t5 = route.type === "page-editor" && /* @__PURE__ */ jsx(PageEditorSidebar, {});
|
|
62
|
-
$[11] = route.type;
|
|
63
|
-
$[12] = t5;
|
|
64
|
-
} else t5 = $[12];
|
|
65
|
-
let t6;
|
|
66
|
-
if ($[13] !== isAddBlockSidebarOpen) {
|
|
67
|
-
t6 = isAddBlockSidebarOpen && /* @__PURE__ */ jsx("div", {
|
|
38
|
+
if ($[7] !== isAddBlockSidebarOpen) {
|
|
39
|
+
t4 = isAddBlockSidebarOpen && /* @__PURE__ */ jsx("div", {
|
|
68
40
|
className: "absolute inset-0 z-20",
|
|
69
41
|
style: { background: "rgba(0, 0, 0, 0.66)" },
|
|
70
|
-
onClick:
|
|
42
|
+
onClick: _temp3
|
|
71
43
|
});
|
|
72
|
-
$[
|
|
73
|
-
$[
|
|
74
|
-
} else
|
|
75
|
-
let
|
|
76
|
-
if ($[
|
|
77
|
-
|
|
44
|
+
$[7] = isAddBlockSidebarOpen;
|
|
45
|
+
$[8] = t4;
|
|
46
|
+
} else t4 = $[8];
|
|
47
|
+
let t5;
|
|
48
|
+
if ($[9] !== t3 || $[10] !== t4) {
|
|
49
|
+
t5 = /* @__PURE__ */ jsxs("aside", {
|
|
78
50
|
className: "bg-background relative flex shrink-0 flex-col border-l-2",
|
|
79
51
|
style: t2,
|
|
80
|
-
children: [
|
|
81
|
-
t3,
|
|
82
|
-
t4,
|
|
83
|
-
t5,
|
|
84
|
-
t6
|
|
85
|
-
]
|
|
52
|
+
children: [t3, t4]
|
|
86
53
|
});
|
|
87
|
-
$[
|
|
88
|
-
$[
|
|
89
|
-
$[
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
} else t7 = $[19];
|
|
93
|
-
return t7;
|
|
54
|
+
$[9] = t3;
|
|
55
|
+
$[10] = t4;
|
|
56
|
+
$[11] = t5;
|
|
57
|
+
} else t5 = $[11];
|
|
58
|
+
return t5;
|
|
94
59
|
};
|
|
95
60
|
function _temp(state) {
|
|
96
61
|
return state.context.selection;
|
|
97
62
|
}
|
|
98
63
|
function _temp2(state_0) {
|
|
99
|
-
return state_0.context.
|
|
100
|
-
}
|
|
101
|
-
function _temp3(state_1) {
|
|
102
|
-
return state_1.context.isAddBlockSidebarOpen;
|
|
64
|
+
return state_0.context.isAddBlockSidebarOpen;
|
|
103
65
|
}
|
|
104
|
-
function
|
|
66
|
+
function _temp3() {
|
|
105
67
|
return previewStore.send({ type: "closeAddBlockSidebar" });
|
|
106
68
|
}
|
|
107
69
|
|
|
@@ -29,8 +29,6 @@ const previewStore = createStore({
|
|
|
29
29
|
isPageEditorSidebarOpen: false,
|
|
30
30
|
isAddBlockSidebarOpen: false,
|
|
31
31
|
addBlockSource: null,
|
|
32
|
-
isAgentChatSidebarOpen: false,
|
|
33
|
-
agentChatPageScaffoldContext: null,
|
|
34
32
|
isCreatePageModalOpen: false,
|
|
35
33
|
editingPageId: null,
|
|
36
34
|
isDraftSwitchDialogOpen: false,
|
|
@@ -40,7 +38,6 @@ const previewStore = createStore({
|
|
|
40
38
|
peekedPagePathname: null,
|
|
41
39
|
skipPeekedBlockExitAnimation: false,
|
|
42
40
|
selection: null,
|
|
43
|
-
pendingAgentBlockFocus: null,
|
|
44
41
|
iframeElement: null,
|
|
45
42
|
previewSource: "draft"
|
|
46
43
|
},
|
|
@@ -117,8 +114,7 @@ const previewStore = createStore({
|
|
|
117
114
|
}),
|
|
118
115
|
setSelection: (context, event) => ({
|
|
119
116
|
...context,
|
|
120
|
-
selection: event.selection
|
|
121
|
-
pendingAgentBlockFocus: null
|
|
117
|
+
selection: event.selection
|
|
122
118
|
}),
|
|
123
119
|
setFocusedBlock: (context, event) => ({
|
|
124
120
|
...context,
|
|
@@ -126,40 +122,17 @@ const previewStore = createStore({
|
|
|
126
122
|
type: "block",
|
|
127
123
|
blockId: event.blockId
|
|
128
124
|
},
|
|
129
|
-
pendingAgentBlockFocus: null,
|
|
130
125
|
peekedBlock: null,
|
|
131
126
|
peekedBlockPosition: null,
|
|
132
127
|
isAddBlockSidebarOpen: false
|
|
133
128
|
}),
|
|
134
|
-
focusAgentBlock: (context, event) => ({
|
|
135
|
-
...context,
|
|
136
|
-
selection: {
|
|
137
|
-
type: "block",
|
|
138
|
-
blockId: event.blockId
|
|
139
|
-
},
|
|
140
|
-
pendingAgentBlockFocus: {
|
|
141
|
-
blockId: event.blockId,
|
|
142
|
-
requestId: (context.pendingAgentBlockFocus?.requestId ?? 0) + 1
|
|
143
|
-
},
|
|
144
|
-
peekedBlock: null,
|
|
145
|
-
peekedBlockPosition: null,
|
|
146
|
-
isAddBlockSidebarOpen: false
|
|
147
|
-
}),
|
|
148
|
-
clearPendingAgentBlockFocus: (context, event) => {
|
|
149
|
-
if (context.pendingAgentBlockFocus?.requestId !== event.requestId) return context;
|
|
150
|
-
return {
|
|
151
|
-
...context,
|
|
152
|
-
pendingAgentBlockFocus: null
|
|
153
|
-
};
|
|
154
|
-
},
|
|
155
129
|
selectItem: (context, event) => ({
|
|
156
130
|
...context,
|
|
157
131
|
selection: {
|
|
158
132
|
type: "item",
|
|
159
133
|
blockId: event.blockId,
|
|
160
134
|
itemId: event.itemId
|
|
161
|
-
}
|
|
162
|
-
pendingAgentBlockFocus: null
|
|
135
|
+
}
|
|
163
136
|
}),
|
|
164
137
|
selectBlockField: (context, event) => ({
|
|
165
138
|
...context,
|
|
@@ -168,8 +141,7 @@ const previewStore = createStore({
|
|
|
168
141
|
blockId: event.blockId,
|
|
169
142
|
fieldName: event.fieldName,
|
|
170
143
|
fieldType: event.fieldType
|
|
171
|
-
}
|
|
172
|
-
pendingAgentBlockFocus: null
|
|
144
|
+
}
|
|
173
145
|
}),
|
|
174
146
|
selectItemField: (context, event) => ({
|
|
175
147
|
...context,
|
|
@@ -179,8 +151,7 @@ const previewStore = createStore({
|
|
|
179
151
|
itemId: event.itemId,
|
|
180
152
|
fieldName: event.fieldName,
|
|
181
153
|
fieldType: event.fieldType
|
|
182
|
-
}
|
|
183
|
-
pendingAgentBlockFocus: null
|
|
154
|
+
}
|
|
184
155
|
}),
|
|
185
156
|
selectParent: (context) => {
|
|
186
157
|
const sel = context.selection;
|
|
@@ -211,13 +182,11 @@ const previewStore = createStore({
|
|
|
211
182
|
},
|
|
212
183
|
clearSelection: (context) => ({
|
|
213
184
|
...context,
|
|
214
|
-
selection: null
|
|
215
|
-
pendingAgentBlockFocus: null
|
|
185
|
+
selection: null
|
|
216
186
|
}),
|
|
217
187
|
setPeekedPage: (context, event) => ({
|
|
218
188
|
...context,
|
|
219
189
|
selection: null,
|
|
220
|
-
pendingAgentBlockFocus: null,
|
|
221
190
|
peekedPagePathname: event.pathname
|
|
222
191
|
}),
|
|
223
192
|
clearPeekedPage: (context) => ({
|
|
@@ -244,7 +213,6 @@ const previewStore = createStore({
|
|
|
244
213
|
type: "block",
|
|
245
214
|
blockId: event.blockId
|
|
246
215
|
},
|
|
247
|
-
pendingAgentBlockFocus: null,
|
|
248
216
|
isAddBlockSidebarOpen: false,
|
|
249
217
|
peekedBlock: null,
|
|
250
218
|
peekedBlockPosition: null,
|
|
@@ -273,28 +241,6 @@ const previewStore = createStore({
|
|
|
273
241
|
...context,
|
|
274
242
|
isPageEditorSidebarOpen: false
|
|
275
243
|
}),
|
|
276
|
-
openAgentChatSidebar: (context, event, enqueue) => {
|
|
277
|
-
const pageScaffoldContext = event?.pageScaffoldContext;
|
|
278
|
-
if (context.isAgentChatSidebarOpen && !pageScaffoldContext) return context;
|
|
279
|
-
enqueue.effect(() => trackClientEvent("agent_chat_opened"));
|
|
280
|
-
return {
|
|
281
|
-
...context,
|
|
282
|
-
isAgentChatSidebarOpen: true,
|
|
283
|
-
agentChatPageScaffoldContext: pageScaffoldContext ? {
|
|
284
|
-
id: Date.now(),
|
|
285
|
-
nickname: pageScaffoldContext.nickname,
|
|
286
|
-
fullPath: pageScaffoldContext.fullPath
|
|
287
|
-
} : context.agentChatPageScaffoldContext
|
|
288
|
-
};
|
|
289
|
-
},
|
|
290
|
-
closeAgentChatSidebar: (context) => ({
|
|
291
|
-
...context,
|
|
292
|
-
isAgentChatSidebarOpen: false
|
|
293
|
-
}),
|
|
294
|
-
clearAgentChatPageScaffoldContext: (context) => ({
|
|
295
|
-
...context,
|
|
296
|
-
agentChatPageScaffoldContext: null
|
|
297
|
-
}),
|
|
298
244
|
openCreatePageModal: (context) => ({
|
|
299
245
|
...context,
|
|
300
246
|
isCreatePageModalOpen: true
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
|
|
5
|
+
//#region src/features/vite/auth.ts
|
|
6
|
+
const AUTH_DIR = path.join(os.homedir(), ".camox");
|
|
7
|
+
const AUTH_FILE = path.join(AUTH_DIR, "auth.json");
|
|
8
|
+
function normalizeUrl(url) {
|
|
9
|
+
return url.replace(/\/+$/, "");
|
|
10
|
+
}
|
|
11
|
+
function readAllTokens() {
|
|
12
|
+
try {
|
|
13
|
+
return JSON.parse(fs.readFileSync(AUTH_FILE, "utf-8"));
|
|
14
|
+
} catch {
|
|
15
|
+
return {};
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function writeAllTokens(tokens) {
|
|
19
|
+
fs.mkdirSync(AUTH_DIR, { recursive: true });
|
|
20
|
+
fs.writeFileSync(AUTH_FILE, JSON.stringify(tokens, null, 2), { mode: 384 });
|
|
21
|
+
}
|
|
22
|
+
function readAuthTokenForUrl(authenticationUrl) {
|
|
23
|
+
const entry = readAllTokens()[normalizeUrl(authenticationUrl)];
|
|
24
|
+
if (entry?.token && entry?.name && typeof entry.email === "string") return entry;
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
function writeAuthTokenForUrl(authenticationUrl, token) {
|
|
28
|
+
const tokens = readAllTokens();
|
|
29
|
+
tokens[normalizeUrl(authenticationUrl)] = token;
|
|
30
|
+
writeAllTokens(tokens);
|
|
31
|
+
}
|
|
32
|
+
async function verifyOneTimeToken(apiUrl, token) {
|
|
33
|
+
const response = await fetch(`${normalizeUrl(apiUrl)}/api/auth/one-time-token/verify`, {
|
|
34
|
+
method: "POST",
|
|
35
|
+
headers: { "Content-Type": "application/json" },
|
|
36
|
+
body: JSON.stringify({ token })
|
|
37
|
+
});
|
|
38
|
+
if (!response.ok) throw new Error(`OTT verification failed: ${response.status}`);
|
|
39
|
+
const data = await response.json();
|
|
40
|
+
const user = data.user;
|
|
41
|
+
if (!user?.name) throw new Error("No user info in verification response");
|
|
42
|
+
const sessionToken = data.session?.token;
|
|
43
|
+
if (!sessionToken) throw new Error("No session token in verification response");
|
|
44
|
+
return {
|
|
45
|
+
name: user.name,
|
|
46
|
+
email: user.email ?? "",
|
|
47
|
+
token: sessionToken
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
export { readAuthTokenForUrl, verifyOneTimeToken, writeAuthTokenForUrl };
|
|
@@ -9,17 +9,17 @@ const SYNC_DEBOUNCE_DELAY_MS = 100;
|
|
|
9
9
|
* This is the core sync logic, independent of ViteDevServer.
|
|
10
10
|
*/
|
|
11
11
|
function throwIfSyncAuthError(error) {
|
|
12
|
-
if (error instanceof Error && error.name === "ORPCError" && error.message.toLowerCase().includes("unauthorized")) throw new Error("[camox] Definition sync failed: invalid
|
|
12
|
+
if (error instanceof Error && error.name === "ORPCError" && error.message.toLowerCase().includes("unauthorized")) throw new Error("[camox] Definition sync failed: invalid or missing credentials.");
|
|
13
13
|
}
|
|
14
14
|
function isNotFoundError(error) {
|
|
15
15
|
return error instanceof Error && error.name === "ORPCError" && error.message.toLowerCase().includes("not found");
|
|
16
16
|
}
|
|
17
17
|
function throwUnknownEnvironmentError(environmentName) {
|
|
18
|
-
throw new Error(`[camox] Environment "${environmentName}" does not exist.
|
|
18
|
+
throw new Error(`[camox] Environment "${environmentName}" does not exist. Run the dev server while authenticated to create your personal environment first.`);
|
|
19
19
|
}
|
|
20
20
|
async function syncDefinitionsToApi(options) {
|
|
21
|
-
const { camoxApp, projectSlug, apiUrl,
|
|
22
|
-
const client = createServerApiClient(apiUrl, environmentName);
|
|
21
|
+
const { camoxApp, projectSlug, apiUrl, environmentName, autoCreate, authToken, deployToken, logger } = options;
|
|
22
|
+
const client = createServerApiClient(apiUrl, environmentName, authToken);
|
|
23
23
|
const blocks = camoxApp.getBlocks();
|
|
24
24
|
const layoutDefinitions = camoxApp.getSerializableLayoutDefinitions();
|
|
25
25
|
const typesUsedInLayouts = /* @__PURE__ */ new Set();
|
|
@@ -40,7 +40,7 @@ async function syncDefinitionsToApi(options) {
|
|
|
40
40
|
try {
|
|
41
41
|
const result = await client.blockDefinitions.sync({
|
|
42
42
|
projectSlug,
|
|
43
|
-
|
|
43
|
+
deployToken,
|
|
44
44
|
autoCreate,
|
|
45
45
|
definitions
|
|
46
46
|
});
|
|
@@ -64,7 +64,7 @@ async function syncDefinitionsToApi(options) {
|
|
|
64
64
|
try {
|
|
65
65
|
layoutSyncResults = await client.layouts.sync({
|
|
66
66
|
projectSlug,
|
|
67
|
-
|
|
67
|
+
deployToken,
|
|
68
68
|
autoCreate,
|
|
69
69
|
layouts: layoutDefinitions
|
|
70
70
|
});
|
|
@@ -99,7 +99,7 @@ async function syncDefinitionsToApi(options) {
|
|
|
99
99
|
if (initialPage) try {
|
|
100
100
|
const result = await client.projects.initializeContent({
|
|
101
101
|
projectSlug,
|
|
102
|
-
|
|
102
|
+
deployToken,
|
|
103
103
|
layoutId: initialPage.layoutId,
|
|
104
104
|
blocks: initialPage.blocks
|
|
105
105
|
});
|
|
@@ -140,10 +140,10 @@ async function ssrLoadModule(server, modulePath) {
|
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
async function syncDefinitions(server, options) {
|
|
143
|
-
const { projectSlug,
|
|
143
|
+
const { projectSlug, apiUrl, environmentName, autoCreate, authToken, deployToken } = options;
|
|
144
144
|
const blocksDirs = [path.resolve(server.config.root, "src/blocks"), path.resolve(server.config.root, "src/camox/blocks")];
|
|
145
145
|
const layoutsDirs = [path.resolve(server.config.root, "src/layouts"), path.resolve(server.config.root, "src/camox/layouts")];
|
|
146
|
-
const client = createServerApiClient(apiUrl, environmentName);
|
|
146
|
+
const client = createServerApiClient(apiUrl, environmentName, authToken);
|
|
147
147
|
async function performInitialSync() {
|
|
148
148
|
const appModule = server.moduleGraph.getModuleById(CAMOX_APP_PATH);
|
|
149
149
|
if (appModule) server.moduleGraph.invalidateModule(appModule);
|
|
@@ -156,9 +156,10 @@ async function syncDefinitions(server, options) {
|
|
|
156
156
|
camoxApp: camoxModule.camoxApp,
|
|
157
157
|
projectSlug,
|
|
158
158
|
apiUrl,
|
|
159
|
-
syncSecret,
|
|
160
159
|
environmentName,
|
|
161
160
|
autoCreate,
|
|
161
|
+
authToken,
|
|
162
|
+
deployToken,
|
|
162
163
|
logger: server.config.logger
|
|
163
164
|
});
|
|
164
165
|
}
|
|
@@ -177,7 +178,7 @@ async function syncDefinitions(server, options) {
|
|
|
177
178
|
try {
|
|
178
179
|
result = await client.blockDefinitions.upsert({
|
|
179
180
|
projectSlug,
|
|
180
|
-
|
|
181
|
+
deployToken,
|
|
181
182
|
blockId: block._internal.id,
|
|
182
183
|
title: block._internal.title,
|
|
183
184
|
description: block._internal.description,
|
|
@@ -199,7 +200,7 @@ async function syncDefinitions(server, options) {
|
|
|
199
200
|
try {
|
|
200
201
|
result = await client.blockDefinitions.delete({
|
|
201
202
|
projectSlug,
|
|
202
|
-
|
|
203
|
+
deployToken,
|
|
203
204
|
blockId
|
|
204
205
|
});
|
|
205
206
|
} catch (error) {
|