robodev 0.21.1 → 0.22.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.
Files changed (29) hide show
  1. package/package.json +1 -1
  2. package/src/emit-starter.test.ts +2 -2
  3. package/templates/auth-chat/.rulesync/skills/media-feature/SKILL.md +6 -6
  4. package/templates/auth-chat/package.json +1 -1
  5. package/templates/backend/api/_lib.ts +40 -15
  6. package/templates/backend/api/planets/[id].ts +23 -8
  7. package/templates/backend/api/planets.ts +14 -9
  8. package/templates/backend/package.json +1 -1
  9. package/templates/empty/package.json +1 -1
  10. package/templates/space/.rulesync/skills/media-feature/SKILL.md +6 -6
  11. package/templates/space/api/_lib.ts +40 -15
  12. package/templates/space/api/planets/[id].ts +23 -8
  13. package/templates/space/api/planets.ts +14 -9
  14. package/templates/space/apps/fe/src/assets/locales/en/translation.json +1 -0
  15. package/templates/space/apps/fe/src/assets/locales/sl/translation.json +1 -0
  16. package/templates/space/apps/fe/src/components/features/planets/details/PlanetEditPage.tsx +69 -33
  17. package/templates/space/apps/fe/src/components/features/planets/list/PlanetCreateModal.tsx +23 -20
  18. package/templates/space/apps/fe/src/utils/planet-form.test.ts +68 -0
  19. package/templates/space/apps/fe/src/utils/planet-form.ts +49 -0
  20. package/templates/space/apps/fe/src/utils/planet-submit.ts +25 -0
  21. package/templates/space/openapi.json +14 -131
  22. package/templates/space/package.json +1 -1
  23. package/templates/backend/api/files/upload-request.ts +0 -48
  24. package/templates/backend/api/files/upload.ts +0 -29
  25. package/templates/space/api/files/upload-request.ts +0 -48
  26. package/templates/space/api/files/upload.ts +0 -29
  27. package/templates/space/apps/fe/src/utils/media-upload-headers.ts +0 -8
  28. package/templates/space/apps/fe/src/utils/media-upload.test.ts +0 -19
  29. package/templates/space/apps/fe/src/utils/media-upload.ts +0 -72
@@ -1,48 +0,0 @@
1
- import { defineApi, z } from "@robodev-ai/sdk";
2
- import { media, PLANET_IMAGE_RESOURCE } from "../_lib";
3
-
4
- const ALLOWED = new Set(["image/jpeg", "image/png", "image/webp"]);
5
- const MAX_BYTES = 2 * 1024 * 1024;
6
-
7
- export const post = defineApi({
8
- auth: "required",
9
- body: z.object({
10
- resourceName: z.string().optional(),
11
- fileName: z.string().min(1),
12
- fileSize: z.number().int().positive(),
13
- mimeType: z.string().optional(),
14
- method: z.string().optional(),
15
- }),
16
- handler: async (ctx) => {
17
- const mimeType = ctx.body.mimeType || "application/octet-stream";
18
- if (ctx.body.fileSize > MAX_BYTES) {
19
- return { status: 400, body: { message: "File is too large" } };
20
- }
21
- if (ctx.body.resourceName === PLANET_IMAGE_RESOURCE && !ALLOWED.has(mimeType)) {
22
- return { status: 400, body: { message: "Unsupported image type" } };
23
- }
24
-
25
- const key = `planet-images/${ctx.user!.id}/${crypto.randomUUID()}-${ctx.body.fileName.replaceAll("/", "-")}`;
26
- const [row] = await ctx.db
27
- .insert(media)
28
- .values({
29
- key,
30
- userId: ctx.user!.id,
31
- resourceName: ctx.body.resourceName || PLANET_IMAGE_RESOURCE,
32
- fileName: ctx.body.fileName,
33
- fileSize: ctx.body.fileSize,
34
- mimeType,
35
- })
36
- .returning();
37
-
38
- return {
39
- id: row!.id,
40
- method: "post",
41
- url: "/api/files/upload",
42
- fields: [
43
- ["id", row!.id],
44
- ["key", key],
45
- ],
46
- };
47
- },
48
- });
@@ -1,29 +0,0 @@
1
- import { defineApi, eq } from "@robodev-ai/sdk";
2
- import { fail, media } from "../_lib";
3
-
4
- export const post = defineApi({
5
- auth: "required",
6
- multipart: true,
7
- handler: async (ctx) => {
8
- const id =
9
- typeof ctx.body === "object" && ctx.body && "id" in ctx.body ? String(ctx.body.id) : "";
10
- const file = ctx.files?.[0];
11
- if (!id || !file) return fail(400, "Missing file upload");
12
-
13
- const [row] = await ctx.db.select().from(media).where(eq(media.id, id)).limit(1);
14
- if (!row) return fail(404, "Media not found");
15
- if (row.userId !== ctx.user!.id) return fail(403, "You can only upload your own media");
16
-
17
- try {
18
- await ctx.storage.upload(row.key, file.data, {
19
- public: true,
20
- contentType: file.mimetype || row.mimeType,
21
- });
22
- } catch (error) {
23
- return fail(503, error instanceof Error ? error.message : "Storage is not configured");
24
- }
25
-
26
- await ctx.db.update(media).set({ uploaded: new Date() }).where(eq(media.id, row.id));
27
- return { ok: true, id: row.id };
28
- },
29
- });
@@ -1,48 +0,0 @@
1
- import { defineApi, z } from "@robodev-ai/sdk";
2
- import { media, PLANET_IMAGE_RESOURCE } from "../_lib";
3
-
4
- const ALLOWED = new Set(["image/jpeg", "image/png", "image/webp"]);
5
- const MAX_BYTES = 2 * 1024 * 1024;
6
-
7
- export const post = defineApi({
8
- auth: "required",
9
- body: z.object({
10
- resourceName: z.string().optional(),
11
- fileName: z.string().min(1),
12
- fileSize: z.number().int().positive(),
13
- mimeType: z.string().optional(),
14
- method: z.string().optional(),
15
- }),
16
- handler: async (ctx) => {
17
- const mimeType = ctx.body.mimeType || "application/octet-stream";
18
- if (ctx.body.fileSize > MAX_BYTES) {
19
- return { status: 400, body: { message: "File is too large" } };
20
- }
21
- if (ctx.body.resourceName === PLANET_IMAGE_RESOURCE && !ALLOWED.has(mimeType)) {
22
- return { status: 400, body: { message: "Unsupported image type" } };
23
- }
24
-
25
- const key = `planet-images/${ctx.user!.id}/${crypto.randomUUID()}-${ctx.body.fileName.replaceAll("/", "-")}`;
26
- const [row] = await ctx.db
27
- .insert(media)
28
- .values({
29
- key,
30
- userId: ctx.user!.id,
31
- resourceName: ctx.body.resourceName || PLANET_IMAGE_RESOURCE,
32
- fileName: ctx.body.fileName,
33
- fileSize: ctx.body.fileSize,
34
- mimeType,
35
- })
36
- .returning();
37
-
38
- return {
39
- id: row!.id,
40
- method: "post",
41
- url: "/api/files/upload",
42
- fields: [
43
- ["id", row!.id],
44
- ["key", key],
45
- ],
46
- };
47
- },
48
- });
@@ -1,29 +0,0 @@
1
- import { defineApi, eq } from "@robodev-ai/sdk";
2
- import { fail, media } from "../_lib";
3
-
4
- export const post = defineApi({
5
- auth: "required",
6
- multipart: true,
7
- handler: async (ctx) => {
8
- const id =
9
- typeof ctx.body === "object" && ctx.body && "id" in ctx.body ? String(ctx.body.id) : "";
10
- const file = ctx.files?.[0];
11
- if (!id || !file) return fail(400, "Missing file upload");
12
-
13
- const [row] = await ctx.db.select().from(media).where(eq(media.id, id)).limit(1);
14
- if (!row) return fail(404, "Media not found");
15
- if (row.userId !== ctx.user!.id) return fail(403, "You can only upload your own media");
16
-
17
- try {
18
- await ctx.storage.upload(row.key, file.data, {
19
- public: true,
20
- contentType: file.mimetype || row.mimeType,
21
- });
22
- } catch (error) {
23
- return fail(503, error instanceof Error ? error.message : "Storage is not configured");
24
- }
25
-
26
- await ctx.db.update(media).set({ uploaded: new Date() }).where(eq(media.id, row.id));
27
- return { ok: true, id: row.id };
28
- },
29
- });
@@ -1,8 +0,0 @@
1
- /** Raw FormData upload headers. Never set Content-Type — the browser must add the multipart boundary. */
2
- export function mediaUploadHeaders(accessToken: string | null): Headers {
3
- const headers = new Headers();
4
- if (accessToken) {
5
- headers.set("Authorization", `Bearer ${accessToken}`);
6
- }
7
- return headers;
8
- }
@@ -1,19 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
-
3
- import { mediaUploadHeaders } from "./media-upload-headers";
4
-
5
- describe("raw FormData upload headers", () => {
6
- it("sends Bearer when a token exists and does not set Content-Type", () => {
7
- const headers = mediaUploadHeaders("test-access-token");
8
-
9
- expect(headers.get("Authorization")).toBe("Bearer test-access-token");
10
- expect(headers.get("Content-Type")).toBeNull();
11
- });
12
-
13
- it("omits Authorization when no token exists and still does not set Content-Type", () => {
14
- const headers = mediaUploadHeaders(null);
15
-
16
- expect(headers.get("Authorization")).toBeNull();
17
- expect(headers.get("Content-Type")).toBeNull();
18
- });
19
- });
@@ -1,72 +0,0 @@
1
- import type { FileUploadRequest } from "@povio/ui";
2
-
3
- import { authTokenStore } from "@/clients/auth-token-store";
4
- import { AppConfig } from "@/config/app.config";
5
- import type { MediaModels } from "@/openapi/media/media.models";
6
- import { MediaQueries } from "@/openapi/media/media.queries";
7
- import { mediaUploadHeaders } from "@/utils/media-upload-headers";
8
-
9
- interface UseMediaUploadHandlerOptions {
10
- resourceName: MediaModels.MediaResourceName;
11
- method?: string;
12
- onUploaded: (media: { id: string; previewUrl: string }) => void;
13
- }
14
-
15
- interface FileUploadOptions {
16
- abortController?: AbortController;
17
- onUploadProgress?: (progress: { loaded: number; total: number }) => void;
18
- }
19
-
20
- export function useMediaUploadHandler({ resourceName, method, onUploaded }: UseMediaUploadHandlerOptions) {
21
- const uploadRequest = MediaQueries.useUploadRequest();
22
-
23
- return async (request: FileUploadRequest, file: File, options?: FileUploadOptions): Promise<{ id: string }> => {
24
- options?.onUploadProgress?.({ loaded: 1, total: 100 });
25
-
26
- const instructions = await uploadRequest.mutateAsync({
27
- data: {
28
- ...request.data,
29
- resourceName,
30
- mimeType: file.type || "application/octet-stream",
31
- method: method ?? "post",
32
- },
33
- });
34
-
35
- if (!instructions.url || !instructions.method || !instructions.id || !instructions.fields) {
36
- throw new Error("Media upload instructions are incomplete");
37
- }
38
-
39
- const formData = new FormData();
40
- instructions.fields.forEach(([key, value]) => {
41
- formData.append(key, value);
42
- });
43
- formData.append("file", file);
44
-
45
- const origin = AppConfig.api.url.replace(/\/+$/, "");
46
- const path = instructions.url;
47
- const uploadUrl = /^https?:\/\//i.test(path)
48
- ? path
49
- : origin
50
- ? `${origin}${path}`
51
- : path.startsWith("/")
52
- ? path
53
- : `/${path}`;
54
-
55
- const response = await fetch(uploadUrl, {
56
- method: instructions.method.toUpperCase(),
57
- body: formData,
58
- headers: mediaUploadHeaders(authTokenStore.getAccessToken()),
59
- signal: options?.abortController?.signal,
60
- });
61
-
62
- if (!response.ok) {
63
- const responseText = await response.text().catch(() => "");
64
- throw new Error(`Media upload failed (${response.status})${responseText ? `: ${responseText}` : ""}`);
65
- }
66
-
67
- options?.onUploadProgress?.({ loaded: 100, total: 100 });
68
- onUploaded({ id: instructions.id, previewUrl: URL.createObjectURL(file) });
69
-
70
- return { id: instructions.id };
71
- };
72
- }