@almadar/sdk 0.1.0-alpha.4 → 0.2.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/AlmadarApp-DgwtnIRy.d.ts +9 -0
- package/dist/client/index.d.ts +3 -3
- package/dist/client/index.js +25 -11
- package/dist/client/index.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +148 -25
- package/dist/index.js.map +1 -1
- package/dist/react/index.d.ts +26 -6
- package/dist/react/index.js +127 -15
- package/dist/react/index.js.map +1 -1
- package/dist/server/express.d.ts +39 -0
- package/dist/server/express.js +472 -0
- package/dist/server/express.js.map +1 -0
- package/dist/server/hono.d.ts +33 -0
- package/dist/server/hono.js +417 -0
- package/dist/server/hono.js.map +1 -0
- package/dist/server/index.d.ts +14 -11
- package/dist/server/index.js +102 -46
- package/dist/server/index.js.map +1 -1
- package/dist/{types-BfWDIOGm.d.ts → types-C6RJADoY.d.ts} +43 -63
- package/package.json +26 -22
package/dist/react/index.d.ts
CHANGED
|
@@ -1,9 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
export { A as AlmadarApp } from '../AlmadarApp-DgwtnIRy.js';
|
|
2
|
+
import react__default from 'react';
|
|
3
|
+
import { OrbitalSchema } from '@almadar/core';
|
|
4
|
+
export { EntityData, EventPayload, OrbitalSchema, SSEEvent } from '@almadar/core';
|
|
4
5
|
export { useEventBus as useOrbBus } from '@almadar/ui/hooks';
|
|
5
|
-
export {
|
|
6
|
+
export { A as AlmadarAppProps, O as OrbitalConfigPanelProps } from '../types-C6RJADoY.js';
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
/**
|
|
9
|
+
* OrbitalConfigPanel — auto-derived control rail for an orbital schema.
|
|
10
|
+
*
|
|
11
|
+
* Finds the first trait that declares a non-empty `config`, filters its fields
|
|
12
|
+
* by the consumer-supplied `exposedTiers`, and renders `@almadar/ui`'s
|
|
13
|
+
* `PropertyInspector`. Every control change deep-clones the schema, writes the
|
|
14
|
+
* new value into the matching field's `default`, and emits the mutated schema
|
|
15
|
+
* so the host can pass it to `OrbPreview`.
|
|
16
|
+
*/
|
|
8
17
|
|
|
9
|
-
|
|
18
|
+
interface OrbitalConfigPanelProps {
|
|
19
|
+
schema: string | OrbitalSchema;
|
|
20
|
+
exposedTiers?: string[];
|
|
21
|
+
position?: 'right' | 'bottom';
|
|
22
|
+
onSchemaChange?: (schema: OrbitalSchema) => void;
|
|
23
|
+
}
|
|
24
|
+
declare function OrbitalConfigPanel({ schema, exposedTiers, position, onSchemaChange, }: OrbitalConfigPanelProps): react__default.ReactElement | null;
|
|
25
|
+
declare namespace OrbitalConfigPanel {
|
|
26
|
+
var displayName: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { OrbitalConfigPanel };
|
package/dist/react/index.js
CHANGED
|
@@ -1,9 +1,92 @@
|
|
|
1
|
-
import { lazy,
|
|
1
|
+
import { lazy, useMemo, useState, useEffect, Suspense } from 'react';
|
|
2
|
+
import { Box, Stack, Typography, PropertyInspector } from '@almadar/ui/components';
|
|
3
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
4
|
import '@almadar/ui/index.css';
|
|
3
|
-
import { jsx } from 'react/jsx-runtime';
|
|
4
5
|
export { useEventBus as useOrbBus } from '@almadar/ui/hooks';
|
|
5
6
|
|
|
6
7
|
// src/react/AlmadarApp.tsx
|
|
8
|
+
function parseSchema(schema) {
|
|
9
|
+
if (typeof schema === "string") {
|
|
10
|
+
return JSON.parse(schema);
|
|
11
|
+
}
|
|
12
|
+
return schema;
|
|
13
|
+
}
|
|
14
|
+
function deepClone(value) {
|
|
15
|
+
return JSON.parse(JSON.stringify(value));
|
|
16
|
+
}
|
|
17
|
+
function findConfigTrait(schema) {
|
|
18
|
+
if (!schema?.orbitals) return null;
|
|
19
|
+
for (const orbital of schema.orbitals) {
|
|
20
|
+
for (const traitRef of orbital.traits ?? []) {
|
|
21
|
+
if (typeof traitRef !== "object" || traitRef === null) continue;
|
|
22
|
+
const trait = traitRef;
|
|
23
|
+
if (trait.config && Object.keys(trait.config).length > 0) {
|
|
24
|
+
const name = "name" in trait && typeof trait.name === "string" ? trait.name : "Config";
|
|
25
|
+
return { name, config: trait.config };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
function applyConfigOverride(schema, field, value) {
|
|
32
|
+
const next = deepClone(schema);
|
|
33
|
+
for (const orbital of next.orbitals ?? []) {
|
|
34
|
+
for (const traitRef of orbital.traits ?? []) {
|
|
35
|
+
if (typeof traitRef !== "object" || traitRef === null) continue;
|
|
36
|
+
const trait = traitRef;
|
|
37
|
+
if (trait.config && field in trait.config) {
|
|
38
|
+
trait.config[field] = { ...trait.config[field], default: value };
|
|
39
|
+
return next;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return next;
|
|
44
|
+
}
|
|
45
|
+
function OrbitalConfigPanel({
|
|
46
|
+
schema,
|
|
47
|
+
exposedTiers,
|
|
48
|
+
position = "right",
|
|
49
|
+
onSchemaChange
|
|
50
|
+
}) {
|
|
51
|
+
const parsed = useMemo(() => parseSchema(schema), [schema]);
|
|
52
|
+
const target = useMemo(() => findConfigTrait(parsed), [parsed]);
|
|
53
|
+
const [values, setValues] = useState({});
|
|
54
|
+
if (!target) return null;
|
|
55
|
+
const sortedConfig = Object.fromEntries(
|
|
56
|
+
Object.entries(target.config).sort(([a], [b]) => a.localeCompare(b))
|
|
57
|
+
);
|
|
58
|
+
const handleChange = (field, value) => {
|
|
59
|
+
setValues((prev) => ({ ...prev, [field]: value }));
|
|
60
|
+
const nextSchema = applyConfigOverride(parsed, field, value);
|
|
61
|
+
onSchemaChange?.(nextSchema);
|
|
62
|
+
};
|
|
63
|
+
const handleReset = () => {
|
|
64
|
+
setValues({});
|
|
65
|
+
onSchemaChange?.(parsed);
|
|
66
|
+
};
|
|
67
|
+
const isHorizontal = position === "bottom";
|
|
68
|
+
return /* @__PURE__ */ jsx(
|
|
69
|
+
Box,
|
|
70
|
+
{
|
|
71
|
+
className: `${isHorizontal ? "w-full border-t" : "h-full w-80 flex-shrink-0 border-l"} border-border bg-card p-3 overflow-y-auto`,
|
|
72
|
+
children: /* @__PURE__ */ jsxs(Stack, { direction: "vertical", gap: "sm", children: [
|
|
73
|
+
/* @__PURE__ */ jsx(Typography, { variant: "caption", weight: "bold", color: "muted", children: "Controls" }),
|
|
74
|
+
/* @__PURE__ */ jsx(
|
|
75
|
+
PropertyInspector,
|
|
76
|
+
{
|
|
77
|
+
title: target.name,
|
|
78
|
+
config: sortedConfig,
|
|
79
|
+
values,
|
|
80
|
+
onChange: handleChange,
|
|
81
|
+
onReset: handleReset,
|
|
82
|
+
tiers: exposedTiers
|
|
83
|
+
}
|
|
84
|
+
)
|
|
85
|
+
] })
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
OrbitalConfigPanel.displayName = "OrbitalConfigPanel";
|
|
7
90
|
var OrbPreviewLazy = lazy(async () => {
|
|
8
91
|
const mod = await import('@almadar/ui/runtime');
|
|
9
92
|
return { default: mod.OrbPreview };
|
|
@@ -12,19 +95,25 @@ var BrowserPlaygroundLazy = lazy(async () => {
|
|
|
12
95
|
const mod = await import('@almadar/ui/runtime');
|
|
13
96
|
return { default: mod.BrowserPlayground };
|
|
14
97
|
});
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}));
|
|
98
|
+
function parseSchema2(schema) {
|
|
99
|
+
if (typeof schema === "string") {
|
|
100
|
+
return JSON.parse(schema);
|
|
101
|
+
}
|
|
102
|
+
return schema;
|
|
103
|
+
}
|
|
104
|
+
function AlmadarApp(props) {
|
|
23
105
|
const mode = props.mode ?? "static";
|
|
24
|
-
|
|
106
|
+
const parsedSchema = useMemo(() => parseSchema2(props.schema), [props.schema]);
|
|
107
|
+
const [controlledSchema, setControlledSchema] = useState(parsedSchema);
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
setControlledSchema(parsedSchema);
|
|
110
|
+
}, [parsedSchema]);
|
|
111
|
+
const effectiveSchema = props.exposedTiers && mode !== "server" ? controlledSchema : parsedSchema;
|
|
112
|
+
const showControls = props.exposedTiers && props.exposedTiers.length > 0 && mode !== "server";
|
|
113
|
+
const preview = mode === "mock" ? /* @__PURE__ */ jsx(
|
|
25
114
|
BrowserPlaygroundLazy,
|
|
26
115
|
{
|
|
27
|
-
schema:
|
|
116
|
+
schema: effectiveSchema,
|
|
28
117
|
mode: "mock",
|
|
29
118
|
initialPagePath: props.initialPagePath,
|
|
30
119
|
height: props.height,
|
|
@@ -33,17 +122,40 @@ var AlmadarApp = forwardRef(function AlmadarApp2(props, ref) {
|
|
|
33
122
|
) : /* @__PURE__ */ jsx(
|
|
34
123
|
OrbPreviewLazy,
|
|
35
124
|
{
|
|
36
|
-
schema:
|
|
125
|
+
schema: effectiveSchema,
|
|
37
126
|
mockData: props.data,
|
|
38
127
|
serverUrl: props.serverUrl,
|
|
39
128
|
initialPagePath: props.initialPagePath,
|
|
40
129
|
height: props.height,
|
|
41
130
|
className: props.className
|
|
42
131
|
}
|
|
132
|
+
);
|
|
133
|
+
if (!showControls) {
|
|
134
|
+
return /* @__PURE__ */ jsx(Suspense, { fallback: null, children: preview });
|
|
135
|
+
}
|
|
136
|
+
const isBottom = props.controlsPosition === "bottom";
|
|
137
|
+
return /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsxs(
|
|
138
|
+
"div",
|
|
139
|
+
{
|
|
140
|
+
className: `flex ${isBottom ? "flex-col" : "flex-row"} w-full h-full`,
|
|
141
|
+
style: { height: props.height },
|
|
142
|
+
children: [
|
|
143
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1 min-w-0", children: preview }),
|
|
144
|
+
/* @__PURE__ */ jsx(
|
|
145
|
+
OrbitalConfigPanel,
|
|
146
|
+
{
|
|
147
|
+
schema: parsedSchema,
|
|
148
|
+
exposedTiers: props.exposedTiers,
|
|
149
|
+
position: props.controlsPosition,
|
|
150
|
+
onSchemaChange: setControlledSchema
|
|
151
|
+
}
|
|
152
|
+
)
|
|
153
|
+
]
|
|
154
|
+
}
|
|
43
155
|
) });
|
|
44
|
-
}
|
|
156
|
+
}
|
|
45
157
|
AlmadarApp.displayName = "AlmadarApp";
|
|
46
158
|
|
|
47
|
-
export { AlmadarApp };
|
|
159
|
+
export { AlmadarApp, OrbitalConfigPanel };
|
|
48
160
|
//# sourceMappingURL=index.js.map
|
|
49
161
|
//# sourceMappingURL=index.js.map
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/react/AlmadarApp.tsx"],"names":["AlmadarApp"],"mappings":";;;;;;AAwBA,IAAM,cAAA,GAAiB,KAAK,YAAY;AACtC,EAAA,MAAM,GAAA,GAAM,MAAM,OAAO,qBAAqB,CAAA;AAC9C,EAAA,OAAO,EAAE,OAAA,EAAS,GAAA,CAAI,UAAA,EAAW;AACnC,CAAC,CAAA;AAED,IAAM,qBAAA,GAAwB,KAAK,YAAY;AAC7C,EAAA,MAAM,GAAA,GAAM,MAAM,OAAO,qBAAqB,CAAA;AAC9C,EAAA,OAAO,EAAE,OAAA,EAAS,GAAA,CAAI,iBAAA,EAAkB;AAC1C,CAAC,CAAA;AAEM,IAAM,UAAA,GAAa,UAAA,CAA2C,SAASA,WAAAA,CAC5E,OACA,GAAA,EACA;AACA,EAAA,MAAM,UAAA,GAAa,OAAiE,IAAI,CAAA;AAExF,EAAA,mBAAA,CAAoB,KAAK,OAAO;AAAA,IAC9B,IAAA,CAAK,OAAO,OAAA,EAAS;AACnB,MAAA,IAAI,UAAA,CAAW,YAAY,IAAA,EAAM;AACjC,MAAA,UAAA,CAAW,OAAA,CAAQ,OAAO,OAAO,CAAA;AAAA,IACnC;AAAA,GACF,CAAE,CAAA;AAEF,EAAA,MAAM,IAAA,GAAO,MAAM,IAAA,IAAQ,QAAA;AAE3B,EAAA,uBACE,GAAA,CAAC,QAAA,EAAA,EAAS,QAAA,EAAU,IAAA,EACjB,mBAAS,MAAA,mBACR,GAAA;AAAA,IAAC,qBAAA;AAAA,IAAA;AAAA,MACC,QAAQ,KAAA,CAAM,MAAA;AAAA,MACd,IAAA,EAAK,MAAA;AAAA,MACL,iBAAiB,KAAA,CAAM,eAAA;AAAA,MACvB,QAAQ,KAAA,CAAM,MAAA;AAAA,MACd,WAAW,KAAA,CAAM;AAAA;AAAA,GACnB,mBAEA,GAAA;AAAA,IAAC,cAAA;AAAA,IAAA;AAAA,MACC,QAAQ,KAAA,CAAM,MAAA;AAAA,MACd,UAAU,KAAA,CAAM,IAAA;AAAA,MAChB,WAAW,KAAA,CAAM,SAAA;AAAA,MACjB,iBAAiB,KAAA,CAAM,eAAA;AAAA,MACvB,QAAQ,KAAA,CAAM,MAAA;AAAA,MACd,WAAW,KAAA,CAAM;AAAA;AAAA,GACnB,EAEJ,CAAA;AAEJ,CAAC;AAED,UAAA,CAAW,WAAA,GAAc,YAAA","file":"index.js","sourcesContent":["'use client';\n\n/**\n * `<AlmadarApp />` — renders an orbital schema in the customer's React tree.\n *\n * Thin facade over `@almadar/ui`'s `OrbPreview` (server-backed) and\n * `BrowserPlayground` (in-browser mock server). The `mode` prop picks the\n * runtime path:\n * - `static`: pure OrbPreview with `mockData`\n * - `mock` : BrowserPlayground (in-browser server, faker-seeded)\n * - `server`: OrbPreview with `serverUrl`\n *\n * Lazy-imports the heavy runtime bundle so the SDK is import-cheap in Next.js\n * server components; the actual render happens client-side under a Suspense\n * boundary. CSS is imported as a side-effect at module load.\n */\n\nimport { lazy, forwardRef, Suspense, useImperativeHandle, useRef } from 'react';\nimport type { EventPayload } from '@almadar/core';\nimport type { AlmadarAppProps, AlmadarAppRef } from '../types';\n// Required global styles. Customers who self-manage Tailwind can import from\n// the (forthcoming) `@almadar/sdk/react/no-css` entry instead.\nimport '@almadar/ui/index.css';\n\nconst OrbPreviewLazy = lazy(async () => {\n const mod = await import('@almadar/ui/runtime');\n return { default: mod.OrbPreview };\n});\n\nconst BrowserPlaygroundLazy = lazy(async () => {\n const mod = await import('@almadar/ui/runtime');\n return { default: mod.BrowserPlayground };\n});\n\nexport const AlmadarApp = forwardRef<AlmadarAppRef, AlmadarAppProps>(function AlmadarApp(\n props,\n ref,\n) {\n const emitterRef = useRef<((event: string, payload?: EventPayload) => void) | null>(null);\n\n useImperativeHandle(ref, () => ({\n emit(event, payload) {\n if (emitterRef.current === null) return;\n emitterRef.current(event, payload);\n },\n }));\n\n const mode = props.mode ?? 'static';\n\n return (\n <Suspense fallback={null}>\n {mode === 'mock' ? (\n <BrowserPlaygroundLazy\n schema={props.schema}\n mode=\"mock\"\n initialPagePath={props.initialPagePath}\n height={props.height}\n className={props.className}\n />\n ) : (\n <OrbPreviewLazy\n schema={props.schema}\n mockData={props.data}\n serverUrl={props.serverUrl}\n initialPagePath={props.initialPagePath}\n height={props.height}\n className={props.className}\n />\n )}\n </Suspense>\n );\n});\n\nAlmadarApp.displayName = 'AlmadarApp';\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/react/OrbitalConfigPanel.tsx","../../src/react/AlmadarApp.tsx"],"names":["parseSchema","useMemo","useState","jsx","jsxs"],"mappings":";;;;;;;AA4BA,SAAS,YAAY,MAAA,EAA+C;AAClE,EAAA,IAAI,OAAO,WAAW,QAAA,EAAU;AAC9B,IAAA,OAAO,IAAA,CAAK,MAAM,MAAM,CAAA;AAAA,EAC1B;AACA,EAAA,OAAO,MAAA;AACT;AAEA,SAAS,UAAa,KAAA,EAAa;AACjC,EAAA,OAAO,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,SAAA,CAAU,KAAK,CAAC,CAAA;AACzC;AAEA,SAAS,gBAAgB,MAAA,EAAwD;AAC/E,EAAA,IAAI,CAAC,MAAA,EAAQ,QAAA,EAAU,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C,EAAA,uBACEA,GAAAA,CAAC,QAAA,EAAA,EAAS,QAAA,EAAU,MAClB,QAAA,kBAAAC,IAAAA;AAAA,IAAC,KAAA;AAAA,IAAA;AAAA,MACC,SAAA,EAAW,CAAA,KAAA,EAAQ,QAAA,GAAW,UAAA,GAAa,UAAU,CAAA,cAAA,CAAA;AAAA,MACrD,KAAA,EAAO,EAAE,MAAA,EAAQ,KAAA,CAAM,MAAA,EAAO;AAAA,MAE9B,QAAA,EAAA;AAAA,wBAAAD,GAAAA,CAAC,KAAA,EAAA,EAAI,SAAA,EAAU,gBAAA,EACZ,QAAA,EAAA,OAAA,EACH,CAAA;AAAA,wBACAA,GAAAA;AAAA,UAAC,kBAAA;AAAA,UAAA;AAAA,YACC,MAAA,EAAQ,YAAA;AAAA,YACR,cAAc,KAAA,CAAM,YAAA;AAAA,YACpB,UAAU,KAAA,CAAM,gBAAA;AAAA,YAChB,cAAA,EAAgB;AAAA;AAAA;AAClB;AAAA;AAAA,GACF,EACF,CAAA;AAEJ;AAEA,UAAA,CAAW,WAAA,GAAc,YAAA","file":"index.js","sourcesContent":["'use client';\n\n/**\n * OrbitalConfigPanel — auto-derived control rail for an orbital schema.\n *\n * Finds the first trait that declares a non-empty `config`, filters its fields\n * by the consumer-supplied `exposedTiers`, and renders `@almadar/ui`'s\n * `PropertyInspector`. Every control change deep-clones the schema, writes the\n * new value into the matching field's `default`, and emits the mutated schema\n * so the host can pass it to `OrbPreview`.\n */\n\nimport React, { useMemo, useState } from 'react';\nimport type {\n ConfigFieldDeclaration,\n DeclaredTraitConfig,\n OrbitalSchema,\n Trait,\n TraitConfigValue,\n} from '@almadar/core';\nimport { PropertyInspector } from '@almadar/ui/components';\nimport { Stack, Box, Typography } from '@almadar/ui/components';\n\ninterface ConfigTraitTarget {\n name: string;\n config: DeclaredTraitConfig;\n}\n\nfunction parseSchema(schema: string | OrbitalSchema): OrbitalSchema {\n if (typeof schema === 'string') {\n return JSON.parse(schema) as OrbitalSchema;\n }\n return schema;\n}\n\nfunction deepClone<T>(value: T): T {\n return JSON.parse(JSON.stringify(value)) as T;\n}\n\nfunction findConfigTrait(schema: OrbitalSchema | null): ConfigTraitTarget | null {\n if (!schema?.orbitals) return null;\n for (const orbital of schema.orbitals) {\n for (const traitRef of orbital.traits ?? []) {\n if (typeof traitRef !== 'object' || traitRef === null) continue;\n const trait = traitRef as Trait | { ref?: string; config?: DeclaredTraitConfig };\n if (trait.config && Object.keys(trait.config).length > 0) {\n const name = 'name' in trait && typeof trait.name === 'string' ? trait.name : 'Config';\n return { name, config: trait.config };\n }\n }\n }\n return null;\n}\n\nfunction applyConfigOverride(\n schema: OrbitalSchema,\n field: string,\n value: TraitConfigValue,\n): OrbitalSchema {\n const next = deepClone(schema);\n for (const orbital of next.orbitals ?? []) {\n for (const traitRef of orbital.traits ?? []) {\n if (typeof traitRef !== 'object' || traitRef === null) continue;\n const trait = traitRef as { config?: Record<string, ConfigFieldDeclaration> };\n if (trait.config && field in trait.config) {\n trait.config[field] = { ...trait.config[field], default: value };\n return next;\n }\n }\n }\n return next;\n}\n\nexport interface OrbitalConfigPanelProps {\n schema: string | OrbitalSchema;\n exposedTiers?: string[];\n position?: 'right' | 'bottom';\n onSchemaChange?: (schema: OrbitalSchema) => void;\n}\n\nexport function OrbitalConfigPanel({\n schema,\n exposedTiers,\n position = 'right',\n onSchemaChange,\n}: OrbitalConfigPanelProps): React.ReactElement | null {\n const parsed = useMemo(() => parseSchema(schema), [schema]);\n const target = useMemo(() => findConfigTrait(parsed), [parsed]);\n const [values, setValues] = useState<Record<string, TraitConfigValue>>({});\n\n if (!target) return null;\n\n const sortedConfig: DeclaredTraitConfig = Object.fromEntries(\n Object.entries(target.config).sort(([a], [b]) => a.localeCompare(b)),\n );\n\n const handleChange = (field: string, value: TraitConfigValue): void => {\n setValues((prev) => ({ ...prev, [field]: value }));\n const nextSchema = applyConfigOverride(parsed, field, value);\n onSchemaChange?.(nextSchema);\n };\n\n const handleReset = (): void => {\n setValues({});\n onSchemaChange?.(parsed);\n };\n\n const isHorizontal = position === 'bottom';\n\n return (\n <Box\n className={`${\n isHorizontal ? 'w-full border-t' : 'h-full w-80 flex-shrink-0 border-l'\n } border-border bg-card p-3 overflow-y-auto`}\n >\n <Stack direction=\"vertical\" gap=\"sm\">\n <Typography variant=\"caption\" weight=\"bold\" color=\"muted\">\n Controls\n </Typography>\n <PropertyInspector\n title={target.name}\n config={sortedConfig}\n values={values}\n onChange={handleChange}\n onReset={handleReset}\n tiers={exposedTiers}\n />\n </Stack>\n </Box>\n );\n}\n\nOrbitalConfigPanel.displayName = 'OrbitalConfigPanel';\n","'use client';\n\n/**\n * `<AlmadarApp />` — renders an orbital schema in the customer's React tree.\n *\n * Thin facade over `@almadar/ui`'s `OrbPreview` (server-backed) and\n * `BrowserPlayground` (in-browser mock server). The `mode` prop picks the\n * runtime path:\n * - `static`: pure OrbPreview with `mockData`\n * - `mock` : BrowserPlayground (in-browser server, faker-seeded)\n * - `server`: OrbPreview with `serverUrl`\n *\n * Lazy-imports the heavy runtime bundle so the SDK is import-cheap in Next.js\n * server components; the actual render happens client-side under a Suspense\n * boundary. CSS is imported as a side-effect at module load.\n */\n\nimport { lazy, Suspense, useEffect, useMemo, useState } from 'react';\nimport type { AlmadarAppProps } from '../types';\nimport type { OrbitalSchema } from '@almadar/core';\nimport { OrbitalConfigPanel } from './OrbitalConfigPanel';\n// Required global styles. Customers who self-manage Tailwind can import from\n// the (forthcoming) `@almadar/sdk/react/no-css` entry instead.\nimport '@almadar/ui/index.css';\n\nconst OrbPreviewLazy = lazy(async () => {\n const mod = await import('@almadar/ui/runtime');\n return { default: mod.OrbPreview };\n});\n\nconst BrowserPlaygroundLazy = lazy(async () => {\n const mod = await import('@almadar/ui/runtime');\n return { default: mod.BrowserPlayground };\n});\n\nfunction parseSchema(schema: string | OrbitalSchema): OrbitalSchema {\n if (typeof schema === 'string') {\n return JSON.parse(schema) as OrbitalSchema;\n }\n return schema;\n}\n\nexport function AlmadarApp(props: AlmadarAppProps) {\n const mode = props.mode ?? 'static';\n const parsedSchema = useMemo(() => parseSchema(props.schema), [props.schema]);\n const [controlledSchema, setControlledSchema] = useState<OrbitalSchema>(parsedSchema);\n\n // Reset controlled schema when the incoming schema changes.\n useEffect(() => {\n setControlledSchema(parsedSchema);\n }, [parsedSchema]);\n\n const effectiveSchema = props.exposedTiers && mode !== 'server' ? controlledSchema : parsedSchema;\n const showControls = props.exposedTiers && props.exposedTiers.length > 0 && mode !== 'server';\n\n const preview = mode === 'mock' ? (\n <BrowserPlaygroundLazy\n schema={effectiveSchema}\n mode=\"mock\"\n initialPagePath={props.initialPagePath}\n height={props.height}\n className={props.className}\n />\n ) : (\n <OrbPreviewLazy\n schema={effectiveSchema}\n mockData={props.data}\n serverUrl={props.serverUrl}\n initialPagePath={props.initialPagePath}\n height={props.height}\n className={props.className}\n />\n );\n\n if (!showControls) {\n return (\n <Suspense fallback={null}>\n {preview}\n </Suspense>\n );\n }\n\n const isBottom = props.controlsPosition === 'bottom';\n\n return (\n <Suspense fallback={null}>\n <div\n className={`flex ${isBottom ? 'flex-col' : 'flex-row'} w-full h-full`}\n style={{ height: props.height }}\n >\n <div className=\"flex-1 min-w-0\">\n {preview}\n </div>\n <OrbitalConfigPanel\n schema={parsedSchema}\n exposedTiers={props.exposedTiers}\n position={props.controlsPosition}\n onSchemaChange={setControlledSchema}\n />\n </div>\n </Suspense>\n );\n}\n\nAlmadarApp.displayName = 'AlmadarApp';\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Request, RequestHandler } from 'express';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `@almadar/sdk/server/express` — Express adapter for the Almadar server handlers.
|
|
5
|
+
*
|
|
6
|
+
* Node-only. The consumer must provide their own `express` installation.
|
|
7
|
+
* This module imports express TYPES only; it is never bundled with express itself.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* import { createGenerateHandler, createEditHandler } from '@almadar/sdk/server/express';
|
|
11
|
+
* app.post('/api/agent/generate', createGenerateHandler({ apiKey }));
|
|
12
|
+
* app.put('/api/agent/edit', createEditHandler({ apiKey }));
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
interface GenerateHandlerOptions {
|
|
16
|
+
/** API key issued from Studio's /settings/sdk panel. */
|
|
17
|
+
apiKey: string;
|
|
18
|
+
/** Defaults to https://studio.almadar.io. */
|
|
19
|
+
baseUrl?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Derive a stable end-user id from the Express request.
|
|
22
|
+
* Falls back to the `x-user-id` request header when omitted.
|
|
23
|
+
*/
|
|
24
|
+
endUserId?: (req: Request) => string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Returns an Express `RequestHandler` that streams a generate call as SSE.
|
|
28
|
+
*
|
|
29
|
+
* Body shape accepted: `{ prompt: string; endUserId?: string; appId?: string }`
|
|
30
|
+
*/
|
|
31
|
+
declare function createGenerateHandler(opts: GenerateHandlerOptions): RequestHandler;
|
|
32
|
+
/**
|
|
33
|
+
* Returns an Express `RequestHandler` that calls `editSchema` and returns JSON.
|
|
34
|
+
*
|
|
35
|
+
* Body shape accepted: `{ appId: string; patch: EditSchemaPatch }`
|
|
36
|
+
*/
|
|
37
|
+
declare function createEditHandler(opts: GenerateHandlerOptions): RequestHandler;
|
|
38
|
+
|
|
39
|
+
export { type GenerateHandlerOptions, createEditHandler, createGenerateHandler };
|