@farm.js/create-app 0.1.0-beta.103 → 0.1.0-beta.105

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/index.js CHANGED
@@ -17,6 +17,174 @@ let node_http = require("node:http");
17
17
  let node_https = require("node:https");
18
18
  let node_os = require("node:os");
19
19
  node_os = require_rolldown_runtime.__toESM(node_os);
20
+ function shadcnComponentTemplate(component) {
21
+ switch (component) {
22
+ case "badge": return `import * as React from "react";
23
+ import { cva, type VariantProps } from "class-variance-authority";
24
+ import { cn } from "@/lib/utils";
25
+
26
+ const badgeVariants = cva(
27
+ "inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
28
+ {
29
+ variants: {
30
+ variant: {
31
+ default: "border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80",
32
+ secondary: "border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
33
+ outline: "text-foreground",
34
+ },
35
+ },
36
+ defaultVariants: {
37
+ variant: "default",
38
+ },
39
+ },
40
+ );
41
+
42
+ export interface BadgeProps
43
+ extends React.HTMLAttributes<HTMLDivElement>,
44
+ VariantProps<typeof badgeVariants> {}
45
+
46
+ export function Badge({ className, variant, ...props }: BadgeProps) {
47
+ return <div className={cn(badgeVariants({ variant }), className)} {...props} />;
48
+ }
49
+
50
+ export { badgeVariants };
51
+ `;
52
+ case "button": return `import * as React from "react";
53
+ import { cva, type VariantProps } from "class-variance-authority";
54
+ import { cn } from "@/lib/utils";
55
+
56
+ const buttonVariants = cva(
57
+ "inline-flex h-9 items-center justify-center whitespace-nowrap rounded-md px-4 py-2 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50",
58
+ {
59
+ variants: {
60
+ variant: {
61
+ default: "bg-primary text-primary-foreground shadow hover:bg-primary/90",
62
+ secondary: "bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
63
+ outline: "border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
64
+ ghost: "hover:bg-accent hover:text-accent-foreground",
65
+ },
66
+ size: {
67
+ default: "h-9 px-4 py-2",
68
+ sm: "h-8 rounded-md px-3 text-xs",
69
+ lg: "h-10 rounded-md px-8",
70
+ },
71
+ },
72
+ defaultVariants: {
73
+ variant: "default",
74
+ size: "default",
75
+ },
76
+ },
77
+ );
78
+
79
+ export interface ButtonProps
80
+ extends React.ButtonHTMLAttributes<HTMLButtonElement>,
81
+ VariantProps<typeof buttonVariants> {}
82
+
83
+ export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
84
+ ({ className, variant, size, ...props }, ref) => {
85
+ return (
86
+ <button
87
+ className={cn(buttonVariants({ variant, size, className }))}
88
+ ref={ref}
89
+ {...props}
90
+ />
91
+ );
92
+ },
93
+ );
94
+ Button.displayName = "Button";
95
+
96
+ export { buttonVariants };
97
+ `;
98
+ case "card": return `import * as React from "react";
99
+ import { cn } from "@/lib/utils";
100
+
101
+ export const Card = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
102
+ ({ className, ...props }, ref) => (
103
+ <div
104
+ ref={ref}
105
+ className={cn("rounded-lg border bg-card text-card-foreground shadow-sm", className)}
106
+ {...props}
107
+ />
108
+ ),
109
+ );
110
+ Card.displayName = "Card";
111
+
112
+ export const CardHeader = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
113
+ ({ className, ...props }, ref) => (
114
+ <div ref={ref} className={cn("flex flex-col space-y-1.5 p-6", className)} {...props} />
115
+ ),
116
+ );
117
+ CardHeader.displayName = "CardHeader";
118
+
119
+ export const CardTitle = React.forwardRef<HTMLHeadingElement, React.HTMLAttributes<HTMLHeadingElement>>(
120
+ ({ className, ...props }, ref) => (
121
+ <h3 ref={ref} className={cn("text-2xl font-semibold leading-none tracking-normal", className)} {...props} />
122
+ ),
123
+ );
124
+ CardTitle.displayName = "CardTitle";
125
+
126
+ export const CardDescription = React.forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLParagraphElement>>(
127
+ ({ className, ...props }, ref) => (
128
+ <p ref={ref} className={cn("text-sm text-muted-foreground", className)} {...props} />
129
+ ),
130
+ );
131
+ CardDescription.displayName = "CardDescription";
132
+
133
+ export const CardContent = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
134
+ ({ className, ...props }, ref) => (
135
+ <div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
136
+ ),
137
+ );
138
+ CardContent.displayName = "CardContent";
139
+
140
+ export const CardFooter = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
141
+ ({ className, ...props }, ref) => (
142
+ <div ref={ref} className={cn("flex items-center p-6 pt-0", className)} {...props} />
143
+ ),
144
+ );
145
+ CardFooter.displayName = "CardFooter";
146
+ `;
147
+ case "input": return `import * as React from "react";
148
+ import { cn } from "@/lib/utils";
149
+
150
+ export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {}
151
+
152
+ export const Input = React.forwardRef<HTMLInputElement, InputProps>(
153
+ ({ className, type, ...props }, ref) => (
154
+ <input
155
+ type={type}
156
+ className={cn(
157
+ "flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
158
+ className,
159
+ )}
160
+ ref={ref}
161
+ {...props}
162
+ />
163
+ ),
164
+ );
165
+ Input.displayName = "Input";
166
+ `;
167
+ case "label": return `import * as React from "react";
168
+ import { cn } from "@/lib/utils";
169
+
170
+ export const Label = React.forwardRef<HTMLLabelElement, React.LabelHTMLAttributes<HTMLLabelElement>>(
171
+ ({ className, ...props }, ref) => (
172
+ <label
173
+ ref={ref}
174
+ className={cn("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70", className)}
175
+ {...props}
176
+ />
177
+ ),
178
+ );
179
+ Label.displayName = "Label";
180
+ `;
181
+ }
182
+ }
183
+ //#endregion
184
+ //#region ../farm-cli/src/ui-registry.ts
185
+ /** Value written into a generated `components.json` as `registries.farm.url`. */
186
+ const UI_REGISTRY_URL_TEMPLATE = "https://farmjs.dev/r/{name}.json";
187
+ //#endregion
20
188
  //#region ../farm-cli/src/ui-feature-registry.ts
21
189
  async function installUIFeature(input) {
22
190
  const feature = input.definition.ui;
@@ -259,6 +427,16 @@ function unkeyApiKeysUIFeature() {
259
427
  ]
260
428
  };
261
429
  }
430
+ function sanityContentUIFeature() {
431
+ return {
432
+ name: "sanity-content",
433
+ description: "Sanity content list UI",
434
+ components: ["badge", "card"],
435
+ needsApiClient: false,
436
+ notes: ["Open \"/integrations/sanity\" to check the Sanity connection."],
437
+ files: () => [componentFile("sanity-content-console.tsx", sanityContentTemplate()), integrationPageFile("sanity", "SanityContentConsole")]
438
+ };
439
+ }
262
440
  function billingUIFeature(input) {
263
441
  return {
264
442
  name: `${input.provider}-billing`,
@@ -561,7 +739,7 @@ function createComponentsJson() {
561
739
  lib: "@/lib",
562
740
  hooks: "@/hooks"
563
741
  },
564
- registries: { farm: { url: "https://farmjs.dev/r/{name}.json" } }
742
+ registries: { farm: { url: UI_REGISTRY_URL_TEMPLATE } }
565
743
  };
566
744
  }
567
745
  function mergeComponentsJson(current, defaults) {
@@ -604,169 +782,6 @@ import type { AppIntegrations } from "./integrations";
604
782
  export const { api, apiClient } = createIntegrations<AppIntegrations>();
605
783
  `;
606
784
  }
607
- function shadcnComponentTemplate(component) {
608
- switch (component) {
609
- case "badge": return `import * as React from "react";
610
- import { cva, type VariantProps } from "class-variance-authority";
611
- import { cn } from "@/lib/utils";
612
-
613
- const badgeVariants = cva(
614
- "inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
615
- {
616
- variants: {
617
- variant: {
618
- default: "border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80",
619
- secondary: "border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
620
- outline: "text-foreground",
621
- },
622
- },
623
- defaultVariants: {
624
- variant: "default",
625
- },
626
- },
627
- );
628
-
629
- export interface BadgeProps
630
- extends React.HTMLAttributes<HTMLDivElement>,
631
- VariantProps<typeof badgeVariants> {}
632
-
633
- export function Badge({ className, variant, ...props }: BadgeProps) {
634
- return <div className={cn(badgeVariants({ variant }), className)} {...props} />;
635
- }
636
-
637
- export { badgeVariants };
638
- `;
639
- case "button": return `import * as React from "react";
640
- import { cva, type VariantProps } from "class-variance-authority";
641
- import { cn } from "@/lib/utils";
642
-
643
- const buttonVariants = cva(
644
- "inline-flex h-9 items-center justify-center whitespace-nowrap rounded-md px-4 py-2 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50",
645
- {
646
- variants: {
647
- variant: {
648
- default: "bg-primary text-primary-foreground shadow hover:bg-primary/90",
649
- secondary: "bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
650
- outline: "border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
651
- ghost: "hover:bg-accent hover:text-accent-foreground",
652
- },
653
- size: {
654
- default: "h-9 px-4 py-2",
655
- sm: "h-8 rounded-md px-3 text-xs",
656
- lg: "h-10 rounded-md px-8",
657
- },
658
- },
659
- defaultVariants: {
660
- variant: "default",
661
- size: "default",
662
- },
663
- },
664
- );
665
-
666
- export interface ButtonProps
667
- extends React.ButtonHTMLAttributes<HTMLButtonElement>,
668
- VariantProps<typeof buttonVariants> {}
669
-
670
- export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
671
- ({ className, variant, size, ...props }, ref) => {
672
- return (
673
- <button
674
- className={cn(buttonVariants({ variant, size, className }))}
675
- ref={ref}
676
- {...props}
677
- />
678
- );
679
- },
680
- );
681
- Button.displayName = "Button";
682
-
683
- export { buttonVariants };
684
- `;
685
- case "card": return `import * as React from "react";
686
- import { cn } from "@/lib/utils";
687
-
688
- export const Card = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
689
- ({ className, ...props }, ref) => (
690
- <div
691
- ref={ref}
692
- className={cn("rounded-lg border bg-card text-card-foreground shadow-sm", className)}
693
- {...props}
694
- />
695
- ),
696
- );
697
- Card.displayName = "Card";
698
-
699
- export const CardHeader = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
700
- ({ className, ...props }, ref) => (
701
- <div ref={ref} className={cn("flex flex-col space-y-1.5 p-6", className)} {...props} />
702
- ),
703
- );
704
- CardHeader.displayName = "CardHeader";
705
-
706
- export const CardTitle = React.forwardRef<HTMLHeadingElement, React.HTMLAttributes<HTMLHeadingElement>>(
707
- ({ className, ...props }, ref) => (
708
- <h3 ref={ref} className={cn("text-2xl font-semibold leading-none tracking-normal", className)} {...props} />
709
- ),
710
- );
711
- CardTitle.displayName = "CardTitle";
712
-
713
- export const CardDescription = React.forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLParagraphElement>>(
714
- ({ className, ...props }, ref) => (
715
- <p ref={ref} className={cn("text-sm text-muted-foreground", className)} {...props} />
716
- ),
717
- );
718
- CardDescription.displayName = "CardDescription";
719
-
720
- export const CardContent = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
721
- ({ className, ...props }, ref) => (
722
- <div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
723
- ),
724
- );
725
- CardContent.displayName = "CardContent";
726
-
727
- export const CardFooter = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
728
- ({ className, ...props }, ref) => (
729
- <div ref={ref} className={cn("flex items-center p-6 pt-0", className)} {...props} />
730
- ),
731
- );
732
- CardFooter.displayName = "CardFooter";
733
- `;
734
- case "input": return `import * as React from "react";
735
- import { cn } from "@/lib/utils";
736
-
737
- export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {}
738
-
739
- export const Input = React.forwardRef<HTMLInputElement, InputProps>(
740
- ({ className, type, ...props }, ref) => (
741
- <input
742
- type={type}
743
- className={cn(
744
- "flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
745
- className,
746
- )}
747
- ref={ref}
748
- {...props}
749
- />
750
- ),
751
- );
752
- Input.displayName = "Input";
753
- `;
754
- case "label": return `import * as React from "react";
755
- import { cn } from "@/lib/utils";
756
-
757
- export const Label = React.forwardRef<HTMLLabelElement, React.LabelHTMLAttributes<HTMLLabelElement>>(
758
- ({ className, ...props }, ref) => (
759
- <label
760
- ref={ref}
761
- className={cn("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70", className)}
762
- {...props}
763
- />
764
- ),
765
- );
766
- Label.displayName = "Label";
767
- `;
768
- }
769
- }
770
785
  function billingPricingTemplate(input) {
771
786
  return `"use client";
772
787
 
@@ -1666,6 +1681,40 @@ export function UnkeyApiKeysConsole() {
1666
1681
  }
1667
1682
  `;
1668
1683
  }
1684
+ function sanityContentTemplate() {
1685
+ return `import { Badge } from "@/components/ui/badge";
1686
+ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
1687
+
1688
+ export function SanityContentConsole() {
1689
+ return (
1690
+ <main className="min-h-screen bg-background px-6 py-12 text-foreground">
1691
+ <section className="mx-auto flex w-full max-w-3xl flex-col gap-6">
1692
+ <div className="space-y-3">
1693
+ <Badge variant="secondary">Sanity</Badge>
1694
+ <h1 className="text-3xl font-semibold tracking-normal">Content</h1>
1695
+ </div>
1696
+ <Card>
1697
+ <CardHeader>
1698
+ <CardTitle className="text-xl">Connected to Sanity</CardTitle>
1699
+ <CardDescription>
1700
+ Query documents with createServerQuery and invalidate them from the Sanity webhook.
1701
+ </CardDescription>
1702
+ </CardHeader>
1703
+ <CardContent className="space-y-3">
1704
+ <code className="block overflow-x-auto rounded-md border bg-muted/30 p-3 text-xs">
1705
+ cms.fetch(&apos;*[_type == &quot;post&quot;]{"{"} title {"}"}&apos;)
1706
+ </code>
1707
+ <p className="text-sm text-muted-foreground">
1708
+ Point a Sanity webhook at /api/sanity/webhook to keep cached pages fresh.
1709
+ </p>
1710
+ </CardContent>
1711
+ </Card>
1712
+ </section>
1713
+ </main>
1714
+ );
1715
+ }
1716
+ `;
1717
+ }
1669
1718
  function unkeyProtectedRouteTemplate() {
1670
1719
  return `export function GET() {
1671
1720
  return Response.json({
@@ -2208,6 +2257,43 @@ export const unkeyIntegration = unkey({
2208
2257
  console.log("[unkey]", event.phase, event.route?.path || "none");
2209
2258
  },
2210
2259
  });
2260
+ `
2261
+ },
2262
+ {
2263
+ provider: "sanity",
2264
+ aliases: ["cms", "sanity-cms"],
2265
+ defaultKey: "cms",
2266
+ packageName: "@farm.js/sanity",
2267
+ fileName: "sanity",
2268
+ exportName: "sanityIntegration",
2269
+ description: "Sanity content with server queries, CDN images, and webhook cache invalidation",
2270
+ env: [
2271
+ "SANITY_PROJECT_ID",
2272
+ "SANITY_DATASET",
2273
+ "SANITY_API_READ_TOKEN",
2274
+ "SANITY_WEBHOOK_SECRET"
2275
+ ],
2276
+ dependencies: { "@sanity/client": "^8.4.0" },
2277
+ ui: sanityContentUIFeature(),
2278
+ template: () => `import { sanity } from "@farm.js/sanity";
2279
+
2280
+ export const sanityIntegration = sanity({
2281
+ projectId: process.env.SANITY_PROJECT_ID,
2282
+ dataset: process.env.SANITY_DATASET,
2283
+ token: process.env.SANITY_API_READ_TOKEN,
2284
+ // The webhook fires before Sanity's CDN updates, so reads go through the API.
2285
+ useCdn: false,
2286
+ webhook: {
2287
+ secret: process.env.SANITY_WEBHOOK_SECRET,
2288
+ onChange(payload) {
2289
+ console.log("[sanity]", payload._type, payload._id);
2290
+ return undefined;
2291
+ },
2292
+ },
2293
+ log(event) {
2294
+ console.log("[sanity]", event.phase, event.route?.path || "none");
2295
+ },
2296
+ });
2211
2297
  `
2212
2298
  }
2213
2299
  ];
@@ -2547,6 +2633,7 @@ const FARM_TELEMETRY_TEMPLATES = [
2547
2633
  "jobs-trigger",
2548
2634
  "polar",
2549
2635
  "resend",
2636
+ "sanity",
2550
2637
  "stripe",
2551
2638
  "supabase",
2552
2639
  "unkey",