@mmapp/react-compiler 0.1.0-alpha.7 → 0.1.0-alpha.9
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/auth-3UK75242.mjs +17 -0
- package/dist/babel/index.d.mts +2 -2
- package/dist/babel/index.d.ts +2 -2
- package/dist/babel/index.js +27 -31
- package/dist/babel/index.mjs +1 -1
- package/dist/chunk-7T6Q5KAA.mjs +7506 -0
- package/dist/chunk-ABYPKRSB.mjs +215 -0
- package/dist/chunk-BZEXUPDH.mjs +175 -0
- package/dist/chunk-J3M4GUS7.mjs +161 -0
- package/dist/chunk-JRGFBWTN.mjs +2918 -0
- package/dist/chunk-R2DD5GTY.mjs +186 -0
- package/dist/chunk-UDDTWG5J.mjs +734 -0
- package/dist/chunk-VLTKQDJ3.mjs +244 -0
- package/dist/chunk-WVYY32LD.mjs +939 -0
- package/dist/chunk-XDVM4YHX.mjs +3450 -0
- package/dist/cli/index.js +4372 -3240
- package/dist/cli/index.mjs +77 -179
- package/dist/codemod/cli.js +1 -1
- package/dist/codemod/cli.mjs +1 -1
- package/dist/codemod/index.d.mts +3 -3
- package/dist/codemod/index.d.ts +3 -3
- package/dist/codemod/index.js +1 -1
- package/dist/codemod/index.mjs +1 -1
- package/dist/deploy-YAJGW6II.mjs +9 -0
- package/dist/dev-server-CrQ041KP.d.mts +79 -0
- package/dist/dev-server-CrQ041KP.d.ts +79 -0
- package/dist/dev-server.d.mts +2 -2
- package/dist/dev-server.d.ts +2 -2
- package/dist/dev-server.js +1240 -120
- package/dist/dev-server.mjs +4 -4
- package/dist/envelope-ChEkuHij.d.mts +265 -0
- package/dist/envelope-ChEkuHij.d.ts +265 -0
- package/dist/envelope.d.mts +2 -2
- package/dist/envelope.d.ts +2 -2
- package/dist/envelope.js +27 -31
- package/dist/envelope.mjs +2 -2
- package/dist/index-CEKyyazf.d.mts +104 -0
- package/dist/index-CEKyyazf.d.ts +104 -0
- package/dist/index.d.mts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +1512 -600
- package/dist/index.mjs +8 -8
- package/dist/init-7FJENUDK.mjs +407 -0
- package/dist/project-compiler-ZB4RUYVL.mjs +10 -0
- package/dist/project-decompiler-U55HQUHW.mjs +7 -0
- package/dist/pull-KOL2QAYQ.mjs +109 -0
- package/dist/seed-KOGEPGOJ.mjs +154 -0
- package/dist/server-VW6UPCHO.mjs +277 -0
- package/dist/testing/index.d.mts +8 -8
- package/dist/testing/index.d.ts +8 -8
- package/dist/testing/index.js +27 -31
- package/dist/testing/index.mjs +1 -1
- package/dist/verify-OQDEQYMS.mjs +1833 -0
- package/dist/vite/index.d.mts +1 -1
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +27 -31
- package/dist/vite/index.mjs +2 -2
- package/examples/authentication/main.workflow.tsx +1 -1
- package/examples/authentication/mm.config.ts +1 -1
- package/examples/authentication/pages/LoginPage.tsx +2 -2
- package/examples/authentication/pages/SignupPage.tsx +2 -2
- package/examples/counter.workflow.tsx +1 -1
- package/examples/dashboard.workflow.tsx +1 -1
- package/examples/invoice-approval/actions/invoice.server.ts +1 -1
- package/examples/invoice-approval/main.workflow.tsx +1 -1
- package/examples/invoice-approval/mm.config.ts +1 -1
- package/examples/invoice-approval/pages/InvoiceDetailPage.tsx +1 -1
- package/examples/invoice-approval/pages/InvoiceFormPage.tsx +1 -1
- package/examples/invoice-approval/pages/InvoiceListPage.tsx +1 -1
- package/examples/todo-app.workflow.tsx +1 -1
- package/examples/uber-app/actions/matching.server.ts +1 -1
- package/examples/uber-app/actions/notifications.server.ts +1 -1
- package/examples/uber-app/actions/payments.server.ts +1 -1
- package/examples/uber-app/actions/pricing.server.ts +1 -1
- package/examples/uber-app/app/admin/analytics.tsx +2 -2
- package/examples/uber-app/app/admin/fleet.tsx +2 -2
- package/examples/uber-app/app/admin/surge-pricing.tsx +2 -2
- package/examples/uber-app/app/driver/dashboard.tsx +2 -2
- package/examples/uber-app/app/driver/earnings.tsx +2 -2
- package/examples/uber-app/app/driver/navigation.tsx +2 -2
- package/examples/uber-app/app/driver/ride-acceptance.tsx +2 -2
- package/examples/uber-app/app/rider/home.tsx +2 -2
- package/examples/uber-app/app/rider/payment-methods.tsx +2 -2
- package/examples/uber-app/app/rider/ride-history.tsx +2 -2
- package/examples/uber-app/app/rider/ride-tracking.tsx +2 -2
- package/examples/uber-app/components/DriverCard.tsx +1 -1
- package/examples/uber-app/components/MapView.tsx +3 -3
- package/examples/uber-app/components/RatingStars.tsx +2 -2
- package/examples/uber-app/components/RideCard.tsx +1 -1
- package/examples/uber-app/mm.config.ts +1 -1
- package/examples/uber-app/workflows/dispute-resolution.workflow.tsx +2 -2
- package/examples/uber-app/workflows/driver-onboarding.workflow.tsx +2 -2
- package/examples/uber-app/workflows/payment-processing.workflow.tsx +2 -2
- package/examples/uber-app/workflows/ride-request.workflow.tsx +2 -2
- package/package.json +7 -14
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// src/cli/deploy.ts
|
|
2
|
+
import { glob } from "glob";
|
|
3
|
+
import { readFileSync, writeFileSync } from "fs";
|
|
4
|
+
import { basename } from "path";
|
|
5
|
+
async function deploy(options) {
|
|
6
|
+
const dir = options.dir ?? "dist/workflows";
|
|
7
|
+
const targetLabel = options.targetName ? ` (target: ${options.targetName})` : "";
|
|
8
|
+
console.log(`[mindmatrix-react] Deploying workflows from ${dir} to ${options.apiUrl}${targetLabel}...`);
|
|
9
|
+
const files = await glob(`${dir}/**/*.workflow.json`);
|
|
10
|
+
if (files.length === 0) {
|
|
11
|
+
console.log(`[mindmatrix-react] No workflow files found in ${dir}`);
|
|
12
|
+
return { created: [], updated: [], versioned: [], skipped: [], failed: [] };
|
|
13
|
+
}
|
|
14
|
+
const result = {
|
|
15
|
+
created: [],
|
|
16
|
+
updated: [],
|
|
17
|
+
versioned: [],
|
|
18
|
+
skipped: [],
|
|
19
|
+
failed: []
|
|
20
|
+
};
|
|
21
|
+
const deployedIRs = [];
|
|
22
|
+
for (const file of files) {
|
|
23
|
+
try {
|
|
24
|
+
const ir = JSON.parse(readFileSync(file, "utf-8"));
|
|
25
|
+
const slug = ir.slug;
|
|
26
|
+
if (options.dryRun) {
|
|
27
|
+
console.log(` [dry-run] Would deploy ${slug} (${basename(file)})`);
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const existing = await fetchExistingDefinition(options.apiUrl, options.token, slug);
|
|
31
|
+
if (!existing) {
|
|
32
|
+
await createDefinition(options.apiUrl, options.token, ir);
|
|
33
|
+
console.log(` \u2713 ${slug} (created)`);
|
|
34
|
+
result.created.push(slug);
|
|
35
|
+
} else if (existing.instanceCount === 0 || options.force) {
|
|
36
|
+
await updateDefinition(options.apiUrl, options.token, existing.id, ir);
|
|
37
|
+
console.log(` \u2713 ${slug} (updated)`);
|
|
38
|
+
result.updated.push(slug);
|
|
39
|
+
} else {
|
|
40
|
+
const newVersion = bumpVersion(existing.version);
|
|
41
|
+
ir.version = newVersion;
|
|
42
|
+
await createDefinition(options.apiUrl, options.token, ir);
|
|
43
|
+
console.log(` \u2713 ${slug} v${newVersion} (new version, ${existing.instanceCount} instances on v${existing.version})`);
|
|
44
|
+
result.versioned.push(slug);
|
|
45
|
+
}
|
|
46
|
+
deployedIRs.push(ir);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
const slug = basename(file).replace(".workflow.json", "");
|
|
49
|
+
const msg = error.message;
|
|
50
|
+
console.error(` \u2717 ${slug}: ${msg}`);
|
|
51
|
+
result.failed.push({ slug, error: msg });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (!options.dryRun) {
|
|
55
|
+
for (const ir of deployedIRs) {
|
|
56
|
+
const serviceResult = await syncServices(options.apiUrl, options.token, ir);
|
|
57
|
+
if (serviceResult) {
|
|
58
|
+
if (!result.services) {
|
|
59
|
+
result.services = { registered: [], updated: [], failed: [] };
|
|
60
|
+
}
|
|
61
|
+
result.services.registered.push(...serviceResult.registered);
|
|
62
|
+
result.services.updated.push(...serviceResult.updated);
|
|
63
|
+
result.services.failed.push(...serviceResult.failed);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (options.reportFile) {
|
|
68
|
+
writeFileSync(options.reportFile, JSON.stringify(result, null, 2), "utf-8");
|
|
69
|
+
console.log(`
|
|
70
|
+
Report written to ${options.reportFile}`);
|
|
71
|
+
}
|
|
72
|
+
const total = result.created.length + result.updated.length + result.versioned.length;
|
|
73
|
+
console.log(
|
|
74
|
+
`
|
|
75
|
+
[mindmatrix-react] Deployed ${total} workflows (${result.created.length} created, ${result.updated.length} updated, ${result.versioned.length} versioned, ${result.failed.length} failed)`
|
|
76
|
+
);
|
|
77
|
+
if (result.services) {
|
|
78
|
+
const svcTotal = result.services.registered.length + result.services.updated.length;
|
|
79
|
+
if (svcTotal > 0 || result.services.failed.length > 0) {
|
|
80
|
+
console.log(
|
|
81
|
+
`[mindmatrix-react] Synced ${svcTotal} services (${result.services.registered.length} registered, ${result.services.updated.length} updated, ${result.services.failed.length} failed)`
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
async function fetchExistingDefinition(apiUrl, token, slug) {
|
|
88
|
+
try {
|
|
89
|
+
const res = await fetch(`${apiUrl}/workflow/definitions?slug=${encodeURIComponent(slug)}`, {
|
|
90
|
+
headers: { Authorization: `Bearer ${token}` }
|
|
91
|
+
});
|
|
92
|
+
if (!res.ok) return null;
|
|
93
|
+
const data = await res.json();
|
|
94
|
+
const definitions = Array.isArray(data) ? data : data.items ?? data.data;
|
|
95
|
+
if (!definitions || definitions.length === 0) return null;
|
|
96
|
+
const def = definitions[0];
|
|
97
|
+
return {
|
|
98
|
+
id: def.id,
|
|
99
|
+
slug: def.slug,
|
|
100
|
+
version: def.version || "0.1.0",
|
|
101
|
+
instanceCount: def.instanceCount ?? def.instance_count ?? 0
|
|
102
|
+
};
|
|
103
|
+
} catch {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async function createDefinition(apiUrl, token, ir) {
|
|
108
|
+
const res = await fetch(`${apiUrl}/workflow/definitions`, {
|
|
109
|
+
method: "POST",
|
|
110
|
+
headers: {
|
|
111
|
+
"Content-Type": "application/json",
|
|
112
|
+
Authorization: `Bearer ${token}`
|
|
113
|
+
},
|
|
114
|
+
body: JSON.stringify(ir)
|
|
115
|
+
});
|
|
116
|
+
if (!res.ok) {
|
|
117
|
+
const errorText = await res.text();
|
|
118
|
+
throw new Error(`Create failed: ${res.status} ${errorText}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
async function updateDefinition(apiUrl, token, id, ir) {
|
|
122
|
+
const { slug: _slug, ...updatePayload } = ir;
|
|
123
|
+
const res = await fetch(`${apiUrl}/workflow/definitions/${id}`, {
|
|
124
|
+
method: "PATCH",
|
|
125
|
+
headers: {
|
|
126
|
+
"Content-Type": "application/json",
|
|
127
|
+
Authorization: `Bearer ${token}`
|
|
128
|
+
},
|
|
129
|
+
body: JSON.stringify(updatePayload)
|
|
130
|
+
});
|
|
131
|
+
if (!res.ok) {
|
|
132
|
+
const errorText = await res.text();
|
|
133
|
+
throw new Error(`Update failed: ${res.status} ${errorText}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function bumpVersion(version) {
|
|
137
|
+
const parts = version.split(".");
|
|
138
|
+
if (parts.length !== 3) return `${version}.1`;
|
|
139
|
+
const patch = parseInt(parts[2], 10) || 0;
|
|
140
|
+
return `${parts[0]}.${parts[1]}.${patch + 1}`;
|
|
141
|
+
}
|
|
142
|
+
async function syncServices(apiUrl, token, ir) {
|
|
143
|
+
const metadata = ir.metadata;
|
|
144
|
+
const orchestration = metadata?.orchestration;
|
|
145
|
+
const services = orchestration?.services;
|
|
146
|
+
if (!services || Object.keys(services).length === 0) return null;
|
|
147
|
+
const result = { registered: [], updated: [], failed: [] };
|
|
148
|
+
for (const [name, config] of Object.entries(services)) {
|
|
149
|
+
try {
|
|
150
|
+
const registration = {
|
|
151
|
+
name,
|
|
152
|
+
connection: {
|
|
153
|
+
type: config.type || "webhook",
|
|
154
|
+
url: config.url,
|
|
155
|
+
queue: config.queue
|
|
156
|
+
},
|
|
157
|
+
actions: config.actions || [],
|
|
158
|
+
labels: config.labels || {}
|
|
159
|
+
};
|
|
160
|
+
const existing = await fetchExistingService(apiUrl, token, name);
|
|
161
|
+
if (existing) {
|
|
162
|
+
await fetch(`${apiUrl}/services/${existing.id}`, {
|
|
163
|
+
method: "PATCH",
|
|
164
|
+
headers: {
|
|
165
|
+
"Content-Type": "application/json",
|
|
166
|
+
Authorization: `Bearer ${token}`
|
|
167
|
+
},
|
|
168
|
+
body: JSON.stringify(registration)
|
|
169
|
+
});
|
|
170
|
+
console.log(` \u2713 service: ${name} (updated)`);
|
|
171
|
+
result.updated.push(name);
|
|
172
|
+
} else {
|
|
173
|
+
const res = await fetch(`${apiUrl}/services`, {
|
|
174
|
+
method: "POST",
|
|
175
|
+
headers: {
|
|
176
|
+
"Content-Type": "application/json",
|
|
177
|
+
Authorization: `Bearer ${token}`
|
|
178
|
+
},
|
|
179
|
+
body: JSON.stringify(registration)
|
|
180
|
+
});
|
|
181
|
+
if (!res.ok) {
|
|
182
|
+
const errorText = await res.text();
|
|
183
|
+
throw new Error(`Register failed: ${res.status} ${errorText}`);
|
|
184
|
+
}
|
|
185
|
+
console.log(` \u2713 service: ${name} (registered)`);
|
|
186
|
+
result.registered.push(name);
|
|
187
|
+
}
|
|
188
|
+
} catch (error) {
|
|
189
|
+
const msg = error.message;
|
|
190
|
+
console.error(` \u2717 service: ${name}: ${msg}`);
|
|
191
|
+
result.failed.push(name);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return result;
|
|
195
|
+
}
|
|
196
|
+
async function fetchExistingService(apiUrl, token, name) {
|
|
197
|
+
try {
|
|
198
|
+
const res = await fetch(`${apiUrl}/services?name=${encodeURIComponent(name)}`, {
|
|
199
|
+
headers: { Authorization: `Bearer ${token}` }
|
|
200
|
+
});
|
|
201
|
+
if (!res.ok) return null;
|
|
202
|
+
const data = await res.json();
|
|
203
|
+
const servicesList = Array.isArray(data) ? data : data.services ?? data.items ?? data.data;
|
|
204
|
+
if (!servicesList || servicesList.length === 0) return null;
|
|
205
|
+
const found = servicesList.find((s) => s.name === name);
|
|
206
|
+
return found ? { id: found.id, name: found.name } : null;
|
|
207
|
+
} catch {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export {
|
|
213
|
+
deploy,
|
|
214
|
+
syncServices
|
|
215
|
+
};
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import {
|
|
2
|
+
babelPlugin
|
|
3
|
+
} from "./chunk-7T6Q5KAA.mjs";
|
|
4
|
+
|
|
5
|
+
// src/vite/index.ts
|
|
6
|
+
import { transformSync } from "@babel/core";
|
|
7
|
+
import { writeFileSync, mkdirSync } from "fs";
|
|
8
|
+
import { dirname, join, relative, basename } from "path";
|
|
9
|
+
function mindmatrixReact(options) {
|
|
10
|
+
const include = options?.include ?? ["**/*.workflow.tsx"];
|
|
11
|
+
const mode = options?.mode ?? "infer";
|
|
12
|
+
const outDir = options?.outDir ?? "dist/workflows";
|
|
13
|
+
const seedOnCompile = options?.seedOnCompile ?? false;
|
|
14
|
+
const apiUrl = options?.apiUrl ?? "http://localhost:4200/api/v1";
|
|
15
|
+
const authToken = options?.authToken ?? process.env.MINDMATRIX_TOKEN;
|
|
16
|
+
let enableSourceMaps = options?.sourceMaps;
|
|
17
|
+
let enableSourceAnnotations = options?.sourceAnnotations;
|
|
18
|
+
let isDev = true;
|
|
19
|
+
const compiledFiles = /* @__PURE__ */ new Map();
|
|
20
|
+
function shouldTransform(id) {
|
|
21
|
+
return include.some((pattern) => {
|
|
22
|
+
const regex = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "<<GLOBSTAR>>").replace(/\*/g, "[^/]*").replace(/<<GLOBSTAR>>/g, ".*").replace(/\?/g, ".");
|
|
23
|
+
return new RegExp(regex).test(id);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
async function seedToApi(ir, filePath) {
|
|
27
|
+
if (!seedOnCompile || !authToken) return;
|
|
28
|
+
try {
|
|
29
|
+
const body = {
|
|
30
|
+
slug: ir.slug,
|
|
31
|
+
name: ir.name,
|
|
32
|
+
version: ir.version,
|
|
33
|
+
category: ir.category || "workflow",
|
|
34
|
+
fields: ir.fields || [],
|
|
35
|
+
states: ir.states || [],
|
|
36
|
+
transitions: ir.transitions || [],
|
|
37
|
+
experience: ir.experience || {},
|
|
38
|
+
metadata: {
|
|
39
|
+
...ir.metadata || {},
|
|
40
|
+
source_file: relative(process.cwd(), filePath),
|
|
41
|
+
compiled_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const resp = await fetch(`${apiUrl}/workflow/definitions`, {
|
|
45
|
+
method: "POST",
|
|
46
|
+
headers: {
|
|
47
|
+
"Content-Type": "application/json",
|
|
48
|
+
"Authorization": `Bearer ${authToken}`
|
|
49
|
+
},
|
|
50
|
+
body: JSON.stringify(body)
|
|
51
|
+
});
|
|
52
|
+
if (resp.ok) {
|
|
53
|
+
console.log(`[mindmatrix-react] Seeded ${ir.slug} to ${apiUrl}`);
|
|
54
|
+
} else if (resp.status === 409) {
|
|
55
|
+
const existing = await fetch(
|
|
56
|
+
`${apiUrl}/workflow/definitions?slug=${encodeURIComponent(ir.slug)}&version=${encodeURIComponent(ir.version)}`,
|
|
57
|
+
{ headers: { "Authorization": `Bearer ${authToken}` } }
|
|
58
|
+
);
|
|
59
|
+
if (existing.ok) {
|
|
60
|
+
const data = await existing.json();
|
|
61
|
+
const defId = Array.isArray(data) ? data[0]?.id : data?.id;
|
|
62
|
+
if (defId) {
|
|
63
|
+
await fetch(`${apiUrl}/workflow/definitions/${defId}`, {
|
|
64
|
+
method: "PATCH",
|
|
65
|
+
headers: {
|
|
66
|
+
"Content-Type": "application/json",
|
|
67
|
+
"Authorization": `Bearer ${authToken}`
|
|
68
|
+
},
|
|
69
|
+
body: JSON.stringify(body)
|
|
70
|
+
});
|
|
71
|
+
console.log(`[mindmatrix-react] Updated ${ir.slug} (PATCH)`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
const text = await resp.text().catch(() => "");
|
|
76
|
+
console.warn(`[mindmatrix-react] Seed failed (${resp.status}): ${text.slice(0, 200)}`);
|
|
77
|
+
}
|
|
78
|
+
} catch (e) {
|
|
79
|
+
console.warn(`[mindmatrix-react] Seed failed:`, e instanceof Error ? e.message : e);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
name: "mindmatrix-react",
|
|
84
|
+
enforce: "pre",
|
|
85
|
+
configResolved(config) {
|
|
86
|
+
isDev = config.command === "serve";
|
|
87
|
+
if (enableSourceMaps === void 0) enableSourceMaps = isDev;
|
|
88
|
+
if (enableSourceAnnotations === void 0) enableSourceAnnotations = isDev;
|
|
89
|
+
},
|
|
90
|
+
transform(code, id) {
|
|
91
|
+
if (!shouldTransform(id)) return null;
|
|
92
|
+
try {
|
|
93
|
+
const wantMaps = enableSourceMaps !== false;
|
|
94
|
+
const result = transformSync(code, {
|
|
95
|
+
filename: id,
|
|
96
|
+
plugins: [[babelPlugin, { mode, filename: id, sourceAnnotations: enableSourceAnnotations }]],
|
|
97
|
+
parserOpts: { plugins: ["jsx", "typescript"] },
|
|
98
|
+
sourceMaps: wantMaps,
|
|
99
|
+
// Embed original source in the source map so debuggers can show .workflow.tsx
|
|
100
|
+
...wantMaps ? { sourceFileName: basename(id) } : {}
|
|
101
|
+
});
|
|
102
|
+
if (!result?.code) return null;
|
|
103
|
+
const metadata = result.metadata || {};
|
|
104
|
+
const ir = metadata.mindmatrixIR;
|
|
105
|
+
const warnings = metadata.mindmatrixWarnings;
|
|
106
|
+
const errors = metadata.mindmatrixErrors;
|
|
107
|
+
if (warnings?.length) {
|
|
108
|
+
for (const w of warnings) {
|
|
109
|
+
console.warn(`[mindmatrix-react] ${basename(id)}: ${w.message}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (errors?.length) {
|
|
113
|
+
for (const e of errors) {
|
|
114
|
+
if (mode === "strict") {
|
|
115
|
+
this.error(`${basename(id)}: ${e.message}`);
|
|
116
|
+
} else {
|
|
117
|
+
this.warn(`${basename(id)}: ${e.message}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (ir) {
|
|
122
|
+
compiledFiles.set(id, ir);
|
|
123
|
+
const outputFileName = basename(id).replace(/\.tsx?$/, ".workflow.json");
|
|
124
|
+
const outputPath = join(process.cwd(), outDir, outputFileName);
|
|
125
|
+
mkdirSync(dirname(outputPath), { recursive: true });
|
|
126
|
+
writeFileSync(outputPath, JSON.stringify(ir, null, 2), "utf-8");
|
|
127
|
+
console.log(`[mindmatrix-react] Compiled ${basename(id)} \u2192 ${outputFileName}`);
|
|
128
|
+
seedToApi(ir, id);
|
|
129
|
+
}
|
|
130
|
+
if (!enableSourceAnnotations && ir) {
|
|
131
|
+
stripSourceAnnotations(ir);
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
code: result.code,
|
|
135
|
+
map: wantMaps ? result.map : void 0
|
|
136
|
+
};
|
|
137
|
+
} catch (error) {
|
|
138
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
139
|
+
if (mode === "strict") {
|
|
140
|
+
this.error(`Failed to compile ${basename(id)}: ${msg}`);
|
|
141
|
+
} else {
|
|
142
|
+
console.error(`[mindmatrix-react] Error compiling ${basename(id)}:`, msg);
|
|
143
|
+
}
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
handleHotUpdate(ctx) {
|
|
148
|
+
if (!shouldTransform(ctx.file)) return;
|
|
149
|
+
console.log(`[mindmatrix-react] HMR: ${basename(ctx.file)} changed`);
|
|
150
|
+
return void 0;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function stripSourceAnnotations(ir) {
|
|
155
|
+
const strip = (obj) => {
|
|
156
|
+
if (!obj || typeof obj !== "object") return;
|
|
157
|
+
if (Array.isArray(obj)) {
|
|
158
|
+
for (const item of obj) strip(item);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const rec = obj;
|
|
162
|
+
delete rec.__source;
|
|
163
|
+
for (const val of Object.values(rec)) {
|
|
164
|
+
if (val && typeof val === "object") strip(val);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
strip(ir.fields);
|
|
168
|
+
strip(ir.states);
|
|
169
|
+
strip(ir.transitions);
|
|
170
|
+
strip(ir.experience);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export {
|
|
174
|
+
mindmatrixReact
|
|
175
|
+
};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__require
|
|
3
|
+
} from "./chunk-CIESM3BP.mjs";
|
|
4
|
+
|
|
5
|
+
// src/cli/auth.ts
|
|
6
|
+
import { readFileSync, writeFileSync, mkdirSync, existsSync, unlinkSync } from "fs";
|
|
7
|
+
import { join } from "path";
|
|
8
|
+
import { homedir } from "os";
|
|
9
|
+
import { createInterface } from "readline";
|
|
10
|
+
var MMRC_DIR = join(homedir(), ".mmrc");
|
|
11
|
+
var CREDENTIALS_PATH = join(MMRC_DIR, "credentials.json");
|
|
12
|
+
function loadCredentials() {
|
|
13
|
+
if (!existsSync(CREDENTIALS_PATH)) return {};
|
|
14
|
+
try {
|
|
15
|
+
return JSON.parse(readFileSync(CREDENTIALS_PATH, "utf-8"));
|
|
16
|
+
} catch {
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function saveCredentials(apiUrl, token) {
|
|
21
|
+
mkdirSync(MMRC_DIR, { recursive: true, mode: 448 });
|
|
22
|
+
const creds = loadCredentials();
|
|
23
|
+
creds[apiUrl] = { token, savedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
24
|
+
writeFileSync(CREDENTIALS_PATH, JSON.stringify(creds, null, 2), "utf-8");
|
|
25
|
+
try {
|
|
26
|
+
const { chmodSync } = __require("fs");
|
|
27
|
+
chmodSync(CREDENTIALS_PATH, 384);
|
|
28
|
+
} catch {
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function removeCredentials(apiUrl) {
|
|
32
|
+
if (!existsSync(CREDENTIALS_PATH)) return;
|
|
33
|
+
if (!apiUrl) {
|
|
34
|
+
unlinkSync(CREDENTIALS_PATH);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const creds = loadCredentials();
|
|
38
|
+
delete creds[apiUrl];
|
|
39
|
+
if (Object.keys(creds).length === 0) {
|
|
40
|
+
unlinkSync(CREDENTIALS_PATH);
|
|
41
|
+
} else {
|
|
42
|
+
writeFileSync(CREDENTIALS_PATH, JSON.stringify(creds, null, 2), "utf-8");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function resolveToken(apiUrl, explicitToken) {
|
|
46
|
+
if (explicitToken) return explicitToken;
|
|
47
|
+
const envToken = process.env.MMRC_TOKEN;
|
|
48
|
+
if (envToken) return envToken;
|
|
49
|
+
const creds = loadCredentials();
|
|
50
|
+
const entry = creds[apiUrl];
|
|
51
|
+
if (entry?.token) return entry.token;
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
function prompt(question, hidden = false) {
|
|
55
|
+
return new Promise((resolve) => {
|
|
56
|
+
const rl = createInterface({
|
|
57
|
+
input: process.stdin,
|
|
58
|
+
output: process.stdout
|
|
59
|
+
});
|
|
60
|
+
if (hidden && process.stdin.isTTY) {
|
|
61
|
+
const origWrite = process.stdout.write.bind(process.stdout);
|
|
62
|
+
process.stdout.write = ((chunk, encodingOrCb, cb) => {
|
|
63
|
+
if (typeof chunk === "string" && chunk.includes(question)) {
|
|
64
|
+
return origWrite(chunk, encodingOrCb, cb);
|
|
65
|
+
}
|
|
66
|
+
if (typeof chunk === "string" && !chunk.includes("\n")) {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
return origWrite(chunk, encodingOrCb, cb);
|
|
70
|
+
});
|
|
71
|
+
rl.question(question, (answer) => {
|
|
72
|
+
process.stdout.write = origWrite;
|
|
73
|
+
console.log();
|
|
74
|
+
rl.close();
|
|
75
|
+
resolve(answer.trim());
|
|
76
|
+
});
|
|
77
|
+
} else {
|
|
78
|
+
rl.question(question, (answer) => {
|
|
79
|
+
rl.close();
|
|
80
|
+
resolve(answer.trim());
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
async function login(apiUrl, email, password) {
|
|
86
|
+
if (!email) {
|
|
87
|
+
email = await prompt("Email: ");
|
|
88
|
+
}
|
|
89
|
+
if (!password) {
|
|
90
|
+
password = await prompt("Password: ", true);
|
|
91
|
+
}
|
|
92
|
+
if (!email || !password) {
|
|
93
|
+
throw new Error("Email and password are required");
|
|
94
|
+
}
|
|
95
|
+
console.log(`[mmrc] Logging in to ${apiUrl}...`);
|
|
96
|
+
const res = await fetch(`${apiUrl}/auth/login`, {
|
|
97
|
+
method: "POST",
|
|
98
|
+
headers: { "Content-Type": "application/json" },
|
|
99
|
+
body: JSON.stringify({ email, password })
|
|
100
|
+
});
|
|
101
|
+
if (!res.ok) {
|
|
102
|
+
const text = await res.text();
|
|
103
|
+
throw new Error(`Login failed: ${res.status} ${text}`);
|
|
104
|
+
}
|
|
105
|
+
const data = await res.json();
|
|
106
|
+
const token = data.token ?? data.access_token ?? data.accessToken;
|
|
107
|
+
if (!token) {
|
|
108
|
+
throw new Error("Login succeeded but no token in response");
|
|
109
|
+
}
|
|
110
|
+
saveCredentials(apiUrl, token);
|
|
111
|
+
const userName = data.name ?? data.user?.name ?? data.user?.email ?? email;
|
|
112
|
+
console.log(`[mmrc] Logged in as ${userName}`);
|
|
113
|
+
console.log(`[mmrc] Token saved to ${CREDENTIALS_PATH}`);
|
|
114
|
+
return token;
|
|
115
|
+
}
|
|
116
|
+
function logout(apiUrl) {
|
|
117
|
+
if (apiUrl) {
|
|
118
|
+
removeCredentials(apiUrl);
|
|
119
|
+
console.log(`[mmrc] Credentials removed for ${apiUrl}`);
|
|
120
|
+
} else {
|
|
121
|
+
removeCredentials();
|
|
122
|
+
console.log("[mmrc] All saved credentials removed");
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
async function whoami(apiUrl) {
|
|
126
|
+
const token = resolveToken(apiUrl);
|
|
127
|
+
if (!token) {
|
|
128
|
+
console.log("[mmrc] Not logged in. Run `mmrc login` to authenticate.");
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
const res = await fetch(`${apiUrl}/auth/me`, {
|
|
133
|
+
headers: { Authorization: `Bearer ${token}` }
|
|
134
|
+
});
|
|
135
|
+
if (!res.ok) {
|
|
136
|
+
if (res.status === 401) {
|
|
137
|
+
console.log("[mmrc] Token is expired or invalid. Run `mmrc login` to re-authenticate.");
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
console.log(`[mmrc] Failed to fetch user info: ${res.status}`);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const user = await res.json();
|
|
144
|
+
console.log(`[mmrc] Logged in to ${apiUrl}`);
|
|
145
|
+
console.log(` Name: ${user.name ?? "(unknown)"}`);
|
|
146
|
+
console.log(` Email: ${user.email ?? "(unknown)"}`);
|
|
147
|
+
if (user.id) console.log(` ID: ${user.id}`);
|
|
148
|
+
if (user.role) console.log(` Role: ${user.role}`);
|
|
149
|
+
} catch (error) {
|
|
150
|
+
console.log(`[mmrc] Could not connect to ${apiUrl}: ${error.message}`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export {
|
|
155
|
+
loadCredentials,
|
|
156
|
+
saveCredentials,
|
|
157
|
+
resolveToken,
|
|
158
|
+
login,
|
|
159
|
+
logout,
|
|
160
|
+
whoami
|
|
161
|
+
};
|