@helloleo/plugins 0.2.16 → 0.2.19

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.
@@ -41,6 +41,29 @@
41
41
 
42
42
  export const INTEGRATION_PROXY_URL = '{{LEO_INTEGRATION_PROXY_URL}}';
43
43
 
44
+ // Multi-environment integrations: the published HelloLeo Cloud Worker has
45
+ // HELLOLEO_ENV=production injected at publish. Forwarding `?env=production`
46
+ // makes the proxy resolve credentials from the project's PRODUCTION integration
47
+ // connection (e.g. your production Odoo) instead of the development one, so a
48
+ // published app talks to production while the preview keeps talking to staging.
49
+ //
50
+ // Reads the flag from the server runtime (Cloudflare Worker / Node) when
51
+ // available; in the browser it's absent and we send no param — the proxy then
52
+ // derives the environment from the request origin, so client-side calls from
53
+ // the published app still resolve to production. Server-side calls (SSR / Cloud
54
+ // Worker) carry no browser origin, which is exactly why the explicit param
55
+ // matters there.
56
+ function proxyUrl(): string {
57
+ // Read via globalThis only (no bare `process` reference) so this compiles in
58
+ // any scaffolded project regardless of whether node types are present.
59
+ const g = globalThis as {
60
+ HELLOLEO_ENV?: string;
61
+ process?: { env?: Record<string, string | undefined> };
62
+ };
63
+ const env = g.HELLOLEO_ENV ?? g.process?.env?.HELLOLEO_ENV;
64
+ return env === 'production' ? `${INTEGRATION_PROXY_URL}?env=production` : INTEGRATION_PROXY_URL;
65
+ }
66
+
44
67
  export interface ProxyRequest {
45
68
  integration: string;
46
69
  endpoint: string;
@@ -58,7 +81,13 @@ export interface ProxyResponse<T = unknown> {
58
81
  export async function callIntegration<T = unknown>(
59
82
  req: ProxyRequest,
60
83
  ): Promise<ProxyResponse<T>> {
61
- const res = await fetch(INTEGRATION_PROXY_URL, {
84
+ if (req.integration.toLowerCase() === 'netsuite') {
85
+ throw new Error(
86
+ 'NetSuite is not proxied -- call it from this app\'s own /auth/netsuite + ' +
87
+ '/api server routes with the signed-in user\'s session, not callIntegration().',
88
+ );
89
+ }
90
+ const res = await fetch(proxyUrl(), {
62
91
  method: 'POST',
63
92
  headers: { 'Content-Type': 'application/json' },
64
93
  body: JSON.stringify({ method: 'POST', ...req }),
@@ -24,20 +24,36 @@ export const SCAFFOLD_TEMPLATES = {
24
24
 
25
25
  export type ScaffoldType = keyof typeof SCAFFOLD_TEMPLATES;
26
26
 
27
+ /**
28
+ * Older template ids that still ship under src/templates/ and stay valid
29
+ * PLUGINS_SCAFFOLD_VERSION pins (a deployment may hold back a version).
30
+ */
31
+ export const LEGACY_TEMPLATES = ["tanstack-start-2026-06-18"] as const;
32
+
27
33
  /** Default template id, kept for callers that predate the `type` param. */
28
34
  export const SCAFFOLD_VERSION = SCAFFOLD_TEMPLATES["tanstack-start"];
29
35
 
30
36
  /**
37
+ * Resolve which template to render.
38
+ *
31
39
  * The container can pin the template via PLUGINS_SCAFFOLD_VERSION (a versioned
32
- * template id, e.g. "tanstack-start-2026-06-18"). Unset or unknown values
33
- * fall back to the tanstack-router template, so a stale env var can never
34
- * reproduce the ENOENT-on-missing-template failure.
40
+ * template id, e.g. "tanstack-start-2026-06-18"); unknown values are ignored
41
+ * so a stale env var can never reproduce the ENOENT-on-missing-template
42
+ * failure. An explicit `type` from the tool call wins the FAMILY (start vs
43
+ * router); the pin still supplies the version when it points inside that
44
+ * family. With neither, the pin decides, falling back to the router template.
35
45
  */
36
- export function resolveTemplateId(): string {
46
+ export function resolveTemplateId(type?: ScaffoldType): string {
37
47
  const version = process.env.PLUGINS_SCAFFOLD_VERSION;
38
- const known: string[] = Object.values(SCAFFOLD_TEMPLATES);
39
- if (version && known.includes(version)) return version;
40
- return SCAFFOLD_TEMPLATES["tanstack-router"];
48
+ const known: string[] = [
49
+ ...Object.values(SCAFFOLD_TEMPLATES),
50
+ ...LEGACY_TEMPLATES,
51
+ ];
52
+ const pinned = version && known.includes(version) ? version : undefined;
53
+ if (type) {
54
+ return pinned?.startsWith(type) ? pinned : SCAFFOLD_TEMPLATES[type];
55
+ }
56
+ return pinned ?? SCAFFOLD_TEMPLATES["tanstack-router"];
41
57
  }
42
58
 
43
59
  /**
@@ -73,18 +89,18 @@ const scaffoldOptionsSchema = z.object({
73
89
  description: z
74
90
  .string()
75
91
  .describe("One sentence describing the app. Used as the meta description."),
76
- // type: z
77
- // .enum(["tanstack-start", "tanstack-router"])
78
- // .optional()
79
- // .describe(
80
- // "Project type. 'tanstack-router': " +
81
- // "client-only SPA with no server and no database — use it only for " +
82
- // "pure frontends that talk to external APIs." +
83
- // "'tanstack-start': SSR app with API routes and a " +
84
- // "database, KV and bucket — use it whenever the app " +
85
- // "needs to persist data or run server-side code (experimental, " +
86
- // "use only if the user expresses a really complexe application idea).",
87
- // ),
92
+ type: z
93
+ .enum(["tanstack-start", "tanstack-router"])
94
+ .optional()
95
+ .describe(
96
+ "Project type. 'tanstack-start': SSR app with API routes and a " +
97
+ "database, KV and bucket — use it whenever the app needs to " +
98
+ "persist data or run server-side code, and always for " +
99
+ "setup_authentication (it needs server routes). " +
100
+ "'tanstack-router': client-only SPA with no server and no database " +
101
+ "— use it only for pure frontends that talk to external APIs. " +
102
+ "Omit to use the deployment's default.",
103
+ ),
88
104
  });
89
105
 
90
106
  /** Kebab-case slug of the product name, for package.json. */
@@ -103,10 +119,10 @@ function slugify(name: string): string {
103
119
  * not part of the template tree). Returns the relative paths written.
104
120
  */
105
121
  export async function writeBaseScaffold(
106
- { name, description }: z.infer<typeof scaffoldOptionsSchema>,
122
+ { name, description, type }: z.infer<typeof scaffoldOptionsSchema>,
107
123
  dir: string,
108
124
  ): Promise<string[]> {
109
- const templateId = resolveTemplateId();
125
+ const templateId = resolveTemplateId(type);
110
126
  const projectUuid = projectUuidFromDir(dir);
111
127
  const created = await renderTemplate(
112
128
  templateId,
@@ -133,15 +149,17 @@ export async function writeBaseScaffold(
133
149
  export const scaffold = tool({
134
150
  description:
135
151
  "Scaffold a new project with React 19, file-based routing (TanStack), " +
136
- "Tailwind v4, shadcn/ui, and react-query. Call this first for any new" +
137
- " project, before writing routes or components.",
152
+ "Tailwind v4, shadcn/ui, and react-query. Two types: 'tanstack-start' " +
153
+ "(SSR, API routes, and a database, KV and bucket via @helloleo/runtime) " +
154
+ "or 'tanstack-router' (client-only SPA, no server, no database). Call " +
155
+ "this first for any new project, before writing routes or components.",
138
156
  args: {
139
157
  name: scaffoldOptionsSchema.shape.name,
140
158
  description: scaffoldOptionsSchema.shape.description,
159
+ type: scaffoldOptionsSchema.shape.type,
141
160
  },
142
161
  async execute(args, context) {
143
- const isStart =
144
- resolveTemplateId() === SCAFFOLD_TEMPLATES["tanstack-start"];
162
+ const isStart = resolveTemplateId(args.type).startsWith("tanstack-start");
145
163
  const created = await writeBaseScaffold(args, context.directory);
146
164
  const uiComponents = created.filter((f) =>
147
165
  f.startsWith("src/components/ui/"),